javascript - Defining "path" to object key with a string -
this question has answer here:
is possible define "path" object
key?
for instance if have object
:
var obj = { hello: { you: "you" } }
i select this:
var path = "hello.you"; obj[path]; //should return "you"
(doesn't work obviously, there way?)
you can try this:
var path = "hello.you"; eval("obj."+path);
Comments
Post a Comment