Using javascript square bracket notation to re-arrange values in object -


i've got object:

servicesselected: {   spw: {     sku: "xyz"   } } 

i need make this:

servicesselected: {   xyz: {     sku: "xyz"   } } 

what i've done far:

myvar = servicesselected.spw.sku //stores "xyz" myvar 

this can't it. following doesn't work. can't use regular dot notation because doesn't support inserting variables, right?

newobject = ["servicesselected"][myvar]sku[myvar] 

try this:

var newobject = new object(); newobject["servicesselected"][myvar]["sku"] = myvar; 

javascript supports object attribute querying double square brackets, dynamic generation of attributes. in case, can query newobject.servicesselected[myvar].sku.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -