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 something like this:
object {name : "bob", phone_number : "911" }
propertiesArray = ["name","phone_number"];
object.propertiesArray[0]; // instead of object.name;
object[propertiesArray[0]]
This will do the trick. Object attributes can be accessed like array indexes using []