Accessing Property Of Object With Variable
If I have an object, with properties like name, phone_number, etc...how can I access those in Javascript with a variable? I want to access the property name in javascript by doing
Solution 1:
object[propertiesArray[0]]
This will do the trick. Object attributes can be accessed like array indexes using []
Solution 2:
You can just use object[propertiesArray[0]]
.
Post a Comment for "Accessing Property Of Object With Variable"