How To Dynamically Access Value Of A Property In Javascript Object?
I have the following Javascript object:- var attributes = { entityData: { Party: 12 }, entityType: 'Party' }; Now I want to fetch dynamically the Party property value so
Solution 1:
whenever you need to access dynamic property you have to use square bracket for accessing property . Syntax: object[propery]
var attributes = {
entityData: {
Party: 12
},
entityType: "Party"
};
alert(attributes.entityData[attributes.entityType]);
alert(attributes.entityData[attributes.entityType]);
Post a Comment for "How To Dynamically Access Value Of A Property In Javascript Object?"