Access Javascript object values -
i'm having hard time getting role(here admin) in javascript object construct.
i thought access value data.roles.data.role doesn't seem case? knows i'm doing wrong?
"data": { "gender": "male", "suffix": "dr." "roles": { "data": { "role": "admin" } }
assuming have inside object, , add missing ,
, }
:
var obj = { // <== added { wrapper "data": { "gender": "male", "suffix": "dr.", // <== comma missing here "roles": { "data": { "role": "admin" } } // === } missing here } }; // <== added } wrapper
then yes, you're correct, it's data.roles.data.role
on object (so before first data
); in case of above:
obj.data.roles.data.role
var obj = { "data": { "gender": "male", "suffix": "dr.", "roles": { "data": { "role": "admin" } } } }; console.log(obj.data.roles.data.role); // "admin"
Comments
Post a Comment