How Do I Get A Property Of An Object By String?
I have an object, in an array. Doing this: alert(myObject.cats[1].nickname); will output 'fluffykins' or whatever the nickname is. Is there a way to access this property by string
Solution 1:
Yes, just use square brackets as usual.
myObject.cats[1][param]
Solution 2:
You can do this:
var test = { 'prop1': 'test' };
alert(test['prop1']);
Post a Comment for "How Do I Get A Property Of An Object By String?"