javascript - How do I make the name of my object dynamic -


i creating new objects in array , want able assign dynamic name can access easier. below sample of looking do. want value 'iwantthisdynamic' able variable can name whatever choose when push array.

i using javascript. ideas? in advance!

myarray = [];  myarray.push({iwantthisdynamic:{'color' : 'red', 'image':'3.jpg'}}); 

you can't arrays since array items accessed index, not key. that's objects for.

myobj = {};  myobj.iwantthisdynamic = {'color' : 'red', 'image':'3.jpg'}; 

or if name dynamic:

var dynname = 'dynamic'; myobj[dynname] = 1; 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -