Object deep dot access. set, get, del methods available
MIT License see LICENSE file.
npm install dobj
var obj = {
a: {
b: {
c: 'test'
}
}
};
dobj(obj).get('a.b.c');
// => 'test'
var obj = {
a: {
b: {
c: 'test'
}
}
};
dobj(obj)
.set('a.b.c', 'ok')
.get('a.b.c');
// => 'ok'
This method sets the property (by path) even if the path does not exists. For example:
var obj = {};
dobj(obj)
.forceSet('a.b.c', 'ok')
.get('a.b.c');
// => 'ok'
var obj = {
a: {
b: {
c: 'test'
}
}
};
dobj(obj)
.del('a.b.c')
.get('a.b.c');
// => undefined
These methods are a "silent" versions of get and del. If you call them on paths that does not exists
no exception will be thrown.
If path is incorrect silentGet
will return undefined
and silentDel will remain silent and return dobj as normal del
.