Namespace: getPathInfo

getPathInfo

.getPathInfo(path, object)

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

The path info consists of an object with the following properties:

  • parent - The parent object of the property referenced by path
  • name - The name of the final property, a number if it was an array indexer
  • value - The value of the property, if it exists, otherwise undefined
  • exists - Whether the property exists or not
Source:

getPathInfo

.hasProperty(object, name)

This allows checking whether an object has named property or numeric array index.

Basically does the same thing as the in operator but works properly with natives and null/undefined values.

var obj = {
    arr: ['a', 'b', 'c']
  , str: 'Hello'
}

The following would be the results.

hasProperty('str', obj);  // true
hasProperty('constructor', obj);  // true
hasProperty('bar', obj);  // false

hasProperty('length', obj.str); // true
hasProperty(1, obj.str);  // true
hasProperty(5, obj.str);  // false

hasProperty('length', obj.arr);  // true
hasProperty(2, obj.arr);  // true
hasProperty(3, obj.arr);  // false
Source: