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;