dot-prop
Get, set, or delete a property from a nested object using a dot path
Install
$ npm install --save dot-prop
Usage
const dotProp = ; // getterdotProp;//=> 'unicorn' dotProp;//=> undefined dotProp;//=> 'default value' dotProp;//=> 'unicorn' // setterconst obj = foo: bar: 'a';dotProp;console;//=> {foo: {bar: 'b'}} dotProp;console;//=> {foo: {bar: 'b', baz: 'x'}} // hasdotProp;//=> true // deleterconst obj = foo: bar: 'a';dotProp;console;//=> {foo: {}} objfoobar = x: 'y' y: 'x';dotProp;console;//=> {foo: {bar: {y: 'x'}}}
API
get(obj, path, [defaultValue])
set(obj, path, value)
has(obj, path)
delete(obj, path)
obj
Type: Object
Object to get, set, or delete the path
value.
path
Type: string
Path of the property in the object, using .
to separate each nested key.
Use \\.
if you have a .
in the key.
value
Type: any
Value to set at path
.
defaultValue
Type: any
Default value.
License
MIT © Sindre Sorhus