resolve("document.body.style.width")
// or
resolve("style.width", document.body)
// or even use array indexes
// (someObject has been defined in the question)
resolve("part.0.size", someObject)
// returns null when intermediate properties are not defined:
resolve('properties.that.do.not.exist', {hello:'world'})
The value inside the brackets can be any expression. Therefore, if the property name is stored in a variable, bracket notation must be used:
var something = {
bar: 'foo'
};
var foo = 'bar';
// both x = something[foo] and something[foo] = x work as expected
console.log(something[foo]);
console.log(something.bar)
This is my solution:
Usage example:
There are two ways to access properties Object:
something.bar
something['bar']
The value inside the brackets can be any expression. Therefore, if the property name is stored in a variable, bracket notation must be used: