1 # dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop)
3 > Get, set, or delete a property from a nested object using a dot path
9 $ npm install --save dot-prop
16 const dotProp = require('dot-prop');
19 dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar');
22 dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep');
25 dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
28 dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
32 const obj = {foo: {bar: 'a'}};
33 dotProp.set(obj, 'foo.bar', 'b');
35 //=> {foo: {bar: 'b'}}
37 const foo = dotProp.set({}, 'foo.bar', 'c');
39 //=> {foo: {bar: 'c'}}
41 dotProp.set(obj, 'foo.baz', 'x');
43 //=> {foo: {bar: 'b', baz: 'x'}}
46 dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar');
50 const obj = {foo: {bar: 'a'}};
51 dotProp.delete(obj, 'foo.bar');
55 obj.foo.bar = {x: 'y', y: 'x'};
56 dotProp.delete(obj, 'foo.bar.x');
58 //=> {foo: {bar: {y: 'x'}}}
64 ### get(obj, path, [defaultValue])
66 ### set(obj, path, value)
78 Object to get, set, or delete the `path` value.
84 Path of the property in the object, using `.` to separate each nested key.
86 Use `\\.` if you have a `.` in the key.
92 Value to set at `path`.
103 MIT © [Sindre Sorhus](https://sindresorhus.com)