Lodash mixins for (deep) object accessing / manipulation.
bower install lodash-deep
- Reference
lodash-deep.min.js
afterlodash.min.js
npm install lodash
npm install lodash-deep
-
var _ = require("lodash"); _.mixin(require("lodash-deep"));
The following mixins are included in lodash-deep
:
Sets a value of a property in an object tree. Any missing objects will be created.
Type: Object
The root object of the object tree.
Type: string
The dot separated propertyPath.
Type: *
The value to set.
Type: Object
var object = {};
_.deepSet(object, 'level1.level2.level3.value', 'value 3');
// -> { level1: { level2: { level3: { value: 'value 3' }}}}
_.deepSet(object, 'level1.level2.level3.value', 'foo');
// -> { level1: { level2: { level3: { value: 'foo' }}}}
Retreives the value of a property in an object tree.
Type: Object
The root object of the object tree.
Type: string
The dot separated propertyPath.
Type: *|undefined
The value, or undefined if it doesn't exists.
var object = {
level1: {
value: 'value 1',
level2: Object.create({
level3: {
value: 'value 3'
}
})
}
};
_.deepGet(object, 'level1.value');
// -> 'value 1'
_.deepGet(object, 'level1.level2.level3.value');
// -> 'value 3'
_.deepGet(object, 'foo.bar.baz');
// -> undefined
Retreives the value of a own property in an object tree.
Type: Object
The root object of the object tree.
Type: string
The dot separated propertyPath.
Type: *|undefined
The value, or undefined if it doesn't exists.
var object = {
level1: {
value: 'value 1',
level2: Object.create({
level3: {
value: 'value 3'
}
})
}
};
_.deepOwn(object, 'level1.value');
// -> 'value 1'
_.deepOwn(object, 'level1.level2.level3.value');
// -> undefined
_.deepOwn(object, 'foo.bar.baz');
// -> undefined
Executes a deep pluck on an collection of object trees.
Type: Object|Array
The collection of object trees.
Type: string
The dot separated propertyPath.
Type: Array
var collection = [
{ level1: { level2: { level3: { value: 1 }}}},
{ level1: { level2: { level3: { value: 2 }}}},
{ level1: { level2: { level3: { value: 3 }}}},
{ level1: { level2: { level3: { value: 4 }}}},
{ level1: { level2: {} }},
{}
];
_.deepPluck(collection, 'level1.level2.level3.value');
// -> [ 1, 2, 3, 4, undefined, undefined ]
Executes a deep check for the existence of a property in an object tree.
Type: Object
The root object of the object tree.
Type: string
The dot separated propertyPath.
Type: boolean
var object = {
level1: {
level2: Object.create({
level3: {
value: 'value 3'
}
})
}
};
_.deepIn(object, 'level1');
// -> true
_.deepIn(object, 'level1.level2');
// -> true
_.deepIn(object, 'level1.level2.level3');
// -> true
_.deepIn(object, 'level1.level2.level3.value');
// -> true
Executes a deep check for the existence of a own property in an object tree.
Type: Object
The root object of the object tree.
Type: string
The dot separated propertyPath.
Type: boolean
var object = {
level1: {
level2: Object.create({
level3: {
value: 'value 3'
}
})
}
};
_.deepHas(object, 'level1');
// -> true
_.deepHas(object, 'level1.level2');
// -> true
_.deepHas(object, 'level1.level2.level3');
// -> false
_.deepHas(object, 'level1.level2.level3.value');
// -> false
In version 1.2.0 function names were simplified. Backward compatibility with the old names remains in place.