Lets say I have an following object:
var obj = {
property: [{key:"value1"},{key:"value2"}]
}
And I have following string property[0].key
How can I obtain value2
using this string inside code?
Basicly I want to de something like this obj["property[1].key"]
If string have only dots, I can use following code:
function get_property_by_string(object, string){
return string.split(".").reduce(function(obj, key) {
return obj[key];
}, object);
}
But with array this code doesn't work. Any suggestions?