Being a beginner in Javascript and after failing with all the available solutions on this site, I am posting this question. I have a variable as given below:
var p =
{
"name": "Country",
"entries": [{
"value": "India",
"synonyms": []
},
{
"value": "USA",
"synonyms": []
}
]
};
If I have an array of hundred countries, how can I loop through entries of variable p and add hundred countries to it?
p.entries.push(...moreCountries)would append all elements ofmoreCountriestop.entries.ponly has two properties, so looping doesn't seem to me necessary? Either way, if you want help you should provide a complete example. That includes examples of the inputs and an example of the desired output. Also this is not JSON, it's an object literal.p.entries.push({"value" : i,"synonyms":array_variable});