json javascript array code example
Example 1: change js to json
var obj = {name: "Martin", age: 30, country: "United States"};
var json = JSON.stringify(obj);
console.log(json);
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
Example 2: convert json object to array javascript
var as = JSON.parse(jstring);
Example 3: json arrays
{
"array": [{1,2,3,4,5,6}]
}
Example 4: js create json array
var employees = {
accounting: []
};
for(var i in someData) {
var item = someData[i];
employees.accounting.push({
"firstName" : item.firstName,
"lastName" : item.lastName,
"age" : item.age
});
}