Mangler.getPath() - DarthJDG/Mangler.js GitHub Wiki
Reads a nested object's item by a path string of keys and indices.
Mangler.getPath(object, path)| Parameter | Type | Default | Description |
|---|---|---|---|
| object | Instance | An object to get a value from. | |
| path | String | The path string of the value to get. |
Returns the item from the object with the corresponding path.
Splits the path parameter to tokens and recursively calls Mangler.get() on object. By default Mangler.js only supports objects, arrays and mangler objects. To add support for other object types, see Mangler.registerType().
person = {
name: 'Fred',
friends: [
{ id: 101, name: 'John' },
{ id: 102, name: 'Mark' }
]
};
Mangler.get(person, 'name'); // Returns 'Fred'
Mangler.get(person, 'friends[1].name'); // Returns 'Mark'