javascript - Adding specific parameters to through for loop -


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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -