Constructor
new PathObject(propertiesopt)
Constructor
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
properties | object | <optional> | {} | Initial literal |
- Source
Example
const po = new PathObject(
{
"a" : "Hello",
"b" : {
"c" : "World"
}
}
);
po.get( "b.c" );
// Returns "World"
po.set( "b.c", "InfrontJS" );
po.get( "b.c" );
// Return "InfrontJS"
po.get( "b.d", "what?" );
// Returns "what?"
Methods
get(path, defaultValueopt) → {*}
Taken from lodash. Refer to: https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L13126
Gets the value at path
of object
. If the resolved value is undefined
, the defaultValue
is returned in its place.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
path | Array | | The path of the property to get. | ||
defaultValue | * | <optional> | null | The value returned for |
- Source
Returns:
Returns the resolved value.
- Type:
- *
Example
const pathObject = new PathObject( { 'a': [{ 'b': { 'c': 3 } }] } );
pathObject.get('a[0].b.c');
// => 3
pathObject.get(['a', '0', 'b', 'c']);
// => 3
pathObject.get('a.b.c', 'default');
// => 'default'