If know that this should work:
var object = {
property: "value"
}
var propertyname = "property";
var propertyvalue = object[propertyname];
But how can I get the property value using the propertyname-variable when the object looks like this?
var object = {
anotherObject: {
property: "value"
}
}
var propertyname = "anotherobject.property";
var propertyvalue = object[propertyname]; // This should not work...
Edit: As suggested, in this case the propertyname could be split on ".". But what if it is an arbitrary levels. Could I construct a for-loop somehow that could get the property-value?