Namespace: getPathValue

getPathValue

.getPathValue(path, object)

This allows the retrieval of values in an object given a string path.

var obj = {
    prop1: {
        arr: ['a', 'b', 'c']
      , str: 'Hello'
    }
  , prop2: {
        arr: [ { nested: 'Universe' } ]
      , str: 'Hello again!'
    }
}

The following would be the results.

getPathValue('prop1.str', obj); // Hello
getPathValue('prop1.att[2]', obj); // b
getPathValue('prop2.arr[0].nested', obj); // Universe
Source: