Question: I'm trying to access a property of an object using a dynamic name. Is this possible?

```
const something = { bar: "Foobar!" };
const foo = 'bar';
something.foo; // The idea is to access something.bar, getting "Foobar!"

```

Answer: 
This is my solution:

```
function resolve(path, obj) {
    return path.split('.').reduce(function(prev, curr) {
        return prev ? prev[curr] : null
    }, obj || self)
}

```

Usage examples:

```
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'})

```
ES5 // Check Deeply Nested Variables
------------------------------------

This simple piece of code can check for deeply nested variable / value existence without having to check each variable along the way... 

```
var getValue = function( s, context ){
    return Function.call( context || null, 'return ' + s )();
}

```

Ex. - a deeply nested array of objects:

```
a = [ 
    {
      b : [
          {
             a : 1,
             b : [
                 {
                    c : 1,
                    d : 2   // we want to check for this
                 }
             ]
           }
      ]
    } 
]

```

Instead of :

```
if(a && a[0] && a[0].b && a[0].b[0] && a[0].b[0].b && a[0].b[0].b[0] && a[0].b[0].b[0].d && a[0].b[0].b[0].d == 2 )  // true

```

We can now :

```
if( getValue('a[0].b[0].b[0].d') == 2 ) // true

```

Cheers!