Object.setPath >= 0.1.4
Purpose
Create a path in an object
Syntax
Object.setPath
(
Objectobj
Stringpath
value= {}
Booleanskip_last_entry= false
);
Parameters
obj
- The object in which to set the path
path
- The path to set
value
- The value to set
skip_last_entry
Return values
Object
Returns the given object
Examples
Create the path with default settings
Object.setPath({}, 'a.b.c');>>> {"a":{"b":{"c":{}}}}
Create the path with the given value
Object.setPath({}, 'a.b.c', 'my-value');>>> {"a":{"b":{"c":"my-value"}}}
Skip setting the value if the last part of the path doesn't exist yet
Object.setPath({}, 'a.b.c', 1, true);>>> {"a":{"b":{}}}
Explicitly set undefined as a value
Object.setPath({}, 'a.b.c', undefined);>>> {"a":{"b":{"c": undefined}}}
Comments