i have similar next json:
{ 'igor': {'password': '12345678', 'color': 'white'), 'ruslan': {'password': '87654321', 'color': 'black') } and have variable
var name = 'igor'; how can password value, using variable detect name? tried next:
obj[name['password']] but returns undefined; tried:
obj.name['password'] as returns undefined. how should value? thanks.
as nano commented, access "password" object key "igor" need use obj[name]['password']. because have 2 objects 1 "igor" key, , 1 "ruslan" key. use
var igor = obj['igor']; var igorspassword = igor['password']; in addition unixarmy's form not wrong, , following correct.
var igor = obj.igor; var igorspassword = igor.password; that being said however, if property name has spaces in it must accessed using obj['property name'] form, cannot done obj.property name since space between property , name serves syntax separator when not in string/regular expression.
Comments
Post a Comment