Answer the question
In order to leave comments, you need to log in
How to create json string js?
Hello, I'm stupid, there is a view file;
[
{
"id": 1,
"hex": "#D92B2C",
"line": "Сокольническая",
"name": "Бульвар Рокоссовского"
},
{
"id": 2,
"hex": "#D92B2C",
"line": "Сокольническая",
"name": "Черкизовская"
},
{
"id": 3,
"hex": "#D92B2C",
"line": "Сокольническая",
"name": "Преображенская площадь"
},
$(document).ready(function(){
$('input.autocomplete').autocomplete({
data: {
"Apple": null,
"Microsoft": null,
},
});
});
$.getJSON( "/files/metro-file.json", function( data ) {
var station_name,line_name,line_hex;
$.each( data, function( key, val ) {
station_name = val.name;
line_name = val.line;
line_hex = val.hex;
items.push({
name: station_name+' ('+line_name+')'
});
});
jsonString = JSON.stringify(items);
console.log(items);
});
Answer the question
In order to leave comments, you need to log in
const result = data.reduce((res, item) => ({...res,[item.name]:null}), {})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question