I Know that there are lots of questions like this here on Stack, but none of then helped me; The problem I'm trying to solve is:
Say I have an (dynamic) object:
var car = {
color: 'red',
doors: 2,
engine: {
fuel: 'diesel',
model: '6 inline'
},
driver: {
name: {
first: 'John',
last: 'Meier',
},
age: 30
}
}
What I want to do is: Have a string inside a variable like var prop = "driver.name.first"
and use it for example as
var driverName = getProp('driver.name.first');
var engineModel = getProp('engine.model');
function getProp(prop){
return car[prop];
}
PS: It's a dynamic object which can even be a totally different one, so that's I can't use like var driverName = car[driver][name][first]
or var driverName = car.driver.name.first