Creating javascript object from simple object -
suppose have object
var io={"name":"battery alarm panel","code":"power max","own":"onm"}
which can access below
io['name'] or io['code'] etc.
but if want create object how can access obj
below code not working error uncaught syntaxerror: unexpected token [
detailobj= { io['name']: { io['code']: { io['own']:"12" } } }
what changes need made in io
object create detailobj
you can't declare object that, using variables inside of object declaration property names. you'll have create object this:
detailobj = {}; detailobj[io['name']] = {}; detailobj[io['name']][io['code']] = {}; detailobj[io['name']][io['code']][io['own']] = "12";
Comments
Post a Comment