being beginner in javascript , after failing available solutions on site, posting question. have variable given below:
var p =  {     "name": "country",     "entries": [{         "value": "india",         "synonyms": []     },     {         "value": "usa",         "synonyms": []     }    ] };   if have array of hundred countries, how can loop through entries of variable p , add hundred countries it?
in es6 can use spread argument task:
//... var arrayofcountries = [   {      "value": "germany",      "synonyms": []   },   {     "value": "russia",     "synonyms": []   } ];   p.entries.push(...arrayofcountries);   or if using es5 or older try concat method:
// ... p.entries = p.entries.concat(arrayofcountries);      
Comments
Post a Comment