deepdash, deepmerge, lodash, merge-deep, object-path, ramda, and underscore are all JavaScript utility libraries that help developers work with objects, especially when dealing with deeply nested data structures. These packages provide functions for tasks like deep merging objects, safely accessing nested properties, and transforming complex data. While some are general-purpose utility belts (lodash, underscore, ramda), others focus on specific problems like deep merging (deepmerge, merge-deep) or path-based object access (object-path). deepdash extends Lodash with deep versions of many of its methods. Professional frontend teams choose among these based on their project's architectural style, immutability requirements, and whether they prefer functional programming paradigms or more traditional utility approaches.
When building complex frontend applications, you often need to work with deeply nested objects — merging configurations, updating nested state, or traversing data structures. The JavaScript ecosystem offers several mature libraries for these tasks, each with distinct philosophies and trade-offs. Let’s compare deepdash, deepmerge, lodash, merge-deep, object-path, ramda, and underscore through the lens of real-world engineering scenarios.
deepmerge is purpose-built for deep object merging with predictable behavior.
import deepmerge from 'deepmerge';
const target = { a: { b: 1 } };
const source = { a: { c: 2 } };
const result = deepmerge(target, source);
// { a: { b: 1, c: 2 } }
lodash provides _.merge() for deep merging, but it mutates the first argument by default (unless you clone it first).
import _ from 'lodash';
const target = { a: { b: 1 } };
const source = { a: { c: 2 } };
const result = _.merge({}, target, source); // Note: {} as first arg to avoid mutation
// { a: { b: 1, c: 2 } }
merge-deep offers a simple, immutable deep merge API.
import mergeDeep from 'merge-deep';
const target = { a: { b: 1 } };
const source = { a: { c: 2 } };
const result = mergeDeep(target, source);
// { a: { b: 1, c: 2 } }
ramda doesn’t include deep merge out of the box, but you can combine R.mergeDeepWith with custom logic.
import * as R from 'ramda';
const target = { a: { b: 1 } };
const source = { a: { c: 2 } };
const result = R.mergeDeepRight(target, source);
// { a: { b: 1, c: 2 } }
underscore has no built-in deep merge — you’d need to implement it manually or use shallow _.extend().
import _ from 'underscore';
const target = { a: { b: 1 } };
const source = { a: { c: 2 } };
const result = _.extend({}, target, source); // Shallow only!
// { a: { c: 2 } } — overwrites entire 'a' property
deepdash extends Lodash with deep versions of many methods, including deep merge.
import _ from 'lodash';
import deepdash from 'deepdash';
const _ = deepdash(_);
const target = { a: { b: 1 } };
const source = { a: { c: 2 } };
const result = _.mergeDeep(target, source);
// { a: { b: 1, c: 2 } }
object-path focuses on path-based access, not merging — so it’s not applicable here.
object-path excels at safe, path-based property access.
import objectPath from 'object-path';
const obj = { a: { b: { c: 42 } } };
const value = objectPath.get(obj, 'a.b.c');
// 42
const missing = objectPath.get(obj, 'a.x.y', 'default');
// 'default'
lodash provides _.get() for similar functionality.
import _ from 'lodash';
const obj = { a: { b: { c: 42 } } };
const value = _.get(obj, 'a.b.c');
// 42
const missing = _.get(obj, 'a.x.y', 'default');
// 'default'
ramda uses R.path() for this purpose.
import * as R from 'ramda';
const obj = { a: { b: { c: 42 } } };
const value = R.path(['a', 'b', 'c'], obj);
// 42
const missing = R.pathOr('default', ['a', 'x', 'y'], obj);
// 'default'
underscore has no built-in path access — you’d need to chain _.property() or write custom logic.
import _ from 'underscore';
const obj = { a: { b: { c: 42 } } };
// No direct equivalent — requires manual implementation
deepdash, deepmerge, and merge-deep don’t focus on property access, so they lack this feature.
ramda is built around functional programming principles: immutable, curried functions that compose well.
import * as R from 'ramda';
const transform = R.pipe(
R.assoc('timestamp', Date.now()),
R.evolve({ count: R.inc })
);
transform({ count: 5 }); // { count: 6, timestamp: 1717020000000 }
lodash and underscore offer a more imperative, utility-belt approach — useful for one-off operations but less composable.
import _ from 'lodash';
const data = { count: 5 };
const transformed = _.assign({}, data, { timestamp: Date.now() });
transformed.count = _.increment(transformed.count); // Note: no _.increment — just example
deepdash enhances Lodash with deep versions of many methods (mapValuesDeep, omitDeep, etc.), making it powerful for nested data transformation.
import _ from 'lodash';
import deepdash from 'deepdash';
const _ = deepdash(_);
const obj = { a: { b: 1, c: null }, d: { e: 2 } };
const cleaned = _.omitDeep(obj, _.isNull);
// { a: { b: 1 }, d: { e: 2 } }
This is a critical distinction in modern frontend development, especially with React and Redux.
lodash: Many methods (like _.merge()) mutate the first argument unless you pass an empty object as the first parameter.deepmerge: Always returns a new object — fully immutable.merge-deep: Also immutable by design.ramda: All functions are immutable and never mutate inputs.underscore: Generally mutable (e.g., _.extend() modifies the first object).deepdash: Follows Lodash’s mutation patterns unless using explicitly immutable variants.object-path: Immutable for reads; set() returns a new object by default (can mutate if you pass { mutable: true }).While we’re not quoting numbers, consider the scope:
deepmerge and merge-deep are tiny, single-purpose libraries.object-path is also minimal and focused.lodash and underscore are large utility belts — you’ll likely import only what you need via tree-shaking.ramda is a full FP library — powerful but broad.deepdash is an extension of Lodash, so it adds to Lodash’s footprint.If your only need is deep object merging (e.g., combining config objects), deepmerge is the gold standard — battle-tested, immutable, and zero surprises.
If you’re already using Lodash for other utilities, lodash’s _.merge() (with an empty initial object) is convenient. If you need deep versions of other Lodash methods (like map, omit, etc.), add deepdash.
If your codebase embraces FP principles, ramda gives you composable, immutable tools — including mergeDeepRight and path.
For frequent safe access to nested properties (e.g., in form handling or API response parsing), object-path or lodash’s _.get() are excellent choices.
underscore is still found in older codebases, but it lacks modern features like deep merging and safe path access. Avoid it in new projects.
| Library | Deep Merge | Safe Path Access | Immutability | FP-Friendly | Best For |
|---|---|---|---|---|---|
deepmerge | ✅ Excellent | ❌ | ✅ | ❌ | Pure deep merging |
merge-deep | ✅ Good | ❌ | ✅ | ❌ | Simple deep merging |
lodash | ✅ (with caveats) | ✅ (_.get) | ❌ (mutable by default) | ❌ | General utility work |
deepdash | ✅ (extends Lodash) | ❌ | ❌ | ❌ | Deep Lodash operations |
object-path | ❌ | ✅ Excellent | ✅ (by default) | ❌ | Nested property access |
ramda | ✅ (mergeDeepRight) | ✅ (path) | ✅ | ✅ | Functional programming |
underscore | ❌ | ❌ | ❌ | ❌ | Legacy projects only |
deepmerge — it’s the most reliable and widely adopted.lodash with careful attention to mutation, or ramda if you prefer FP.object-path or lodash.get are both solid.underscore in new projects — it hasn’t kept pace with modern JavaScript patterns.deepdash only if you’re heavily invested in Lodash and need deep versions of many methods.Remember: the best library is the one that matches your team’s style, project constraints, and long-term maintainability goals. Don’t add dependencies you don’t need — sometimes a small utility function is better than a full library.
Choose deepdash if you're already using Lodash and need deep versions of Lodash methods like mapValues, omit, or pick that work recursively on nested objects. It's particularly useful when you have complex nested data transformations that go beyond simple merging. However, be aware that it inherits Lodash's mutation behavior unless you explicitly use immutable variants, and it adds to your bundle size on top of Lodash itself.
Choose deepmerge if your primary need is reliable, immutable deep object merging with predictable behavior. It's the most widely adopted solution for this specific problem and handles edge cases like arrays, dates, and custom merge strategies well. It's ideal for configuration merging, state updates, or any scenario where you need to combine nested objects without side effects.
Choose lodash if you need a comprehensive utility library that covers a wide range of operations beyond just deep object manipulation. Its _.merge() and _.get() methods handle common deep object tasks, though you must remember to pass an empty object as the first argument to _.merge() to avoid mutation. Lodash is well-suited for projects that require diverse utility functions and benefit from tree-shaking to minimize bundle impact.
Choose merge-deep if you want a lightweight, immutable alternative to deepmerge with a simpler API. It's good for basic deep merging scenarios where you don't need advanced customization options like custom merge strategies. However, it's less battle-tested than deepmerge and may not handle as many edge cases, so evaluate carefully for production-critical merging logic.
Choose object-path if your main challenge is safely accessing, setting, or deleting deeply nested properties using string paths. It excels at scenarios like form handling, dynamic configuration, or working with API responses where you need to read/write nested values without worrying about undefined intermediate properties. It's not suitable for deep merging or complex transformations, but it's excellent for its specific purpose.
Choose ramda if your codebase embraces functional programming principles and you need immutable, composable functions for working with objects. Its mergeDeepRight, path, and pathOr functions handle deep merging and property access elegantly, and everything composes well with other Ramda utilities. It's ideal for teams comfortable with FP concepts who want to avoid mutation entirely and build pipelines of data transformations.
Choose underscore only if you're maintaining a legacy codebase that already depends on it. It lacks modern features like deep merging and safe nested property access, and its API feels dated compared to alternatives. For new projects, prefer lodash (which was inspired by Underscore but is more actively maintained and feature-rich) or more specialized libraries based on your specific needs.
eachDeep, filterDeep, findDeep, someDeep, omitDeep, pickDeep, keysDeep etc.. Tree traversal library written in Underscore/Lodash fashion. Standalone or as a Lodash mixin extension
Deepdash lib is used in PlanZed.org - awesome cloud mind map app created by the author of deepdash.
Plz check it, it's free and I need feedback 😉
Load script after Lodash, then pass a lodash instance to the deepdash function:
<script src="https://cdn.jsdelivr.net/npm/lodash/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/deepdash/browser/deepdash.min.js"></script>
<script>
deepdash(_);
console.log(_.eachDeep); // --> new methods mixed into Lodash
</script>
If you don't use Lodash - there is a standalone version:
<script src="https://cdn.jsdelivr.net/npm/deepdash/browser/deepdash.standalone.min.js"></script>
<script>
console.log(deepdash.eachDeep); // --> all the methods just work
</script>
Standalone Deepdash weighs more then "dry" version, because it includes some of cherry-picked Lodash methods it depends on. But it's better to use Standalone version, than include full Lodash just as dependency, if you don't need Lodash.
npm i --save deepdash
In Node.js:
// load Lodash if you need it
const _ = require('lodash');
//mixin all the methods into Lodash object
require('deepdash')(_);
// or cherry-pick method you only need and mix it into lodash
require('deepdash/addFilterDeep')(_);
// or cherry-pick method separately if you don't want to mutate Lodash instance
const filterDeep = require('deepdash/getFilterDeep')(_);
// If you don't need Lodash - there is standalone version
const deepdash = require('deepdash/standalone'); // full
const filterDeep = require('deepdash/filterDeep'); // or separate standalone methods
There is also deepdash as ES6 module
npm i --save deepdash-es
import lodash from 'lodash-es';
import deepdash from 'deepdash-es';
const _ = deepdash(lodash);
in the ES package there are same cherry-pick and/or standalone methods as in the main package.
import filterDeep from 'deepdash-es/filterDeep';
or
import { filterDeep } from 'deepdash-es/standalone';
or
import _ from 'lodash-es';
import getFilterDeep from 'deepdash-es/getFilterDeep';
const filterDeep = getFilterDeep(_);
or
import _ from 'lodash-es';
import addFilterDeep from 'deepdash-es/addFilterDeep';
addFilterDeep(_);// --> _.filterDeep
Example react+redux app with nested comments filtered by Deepdash.(source is here)
› iterate over all the children and sub-children 📚 see docs
let children = [
{
description: 'description for node 1',
comment: 'comment for node 1',
note: 'note for node 1',
name: 'node 1',
bad: false,
children: [
{
description: 'description for node 1.1',
comment: 'comment for node 1.1',
note: 'note for node 1.1',
name: 'node 1.1',
bad: false,
},
{
description: 'description for node 1.2',
comment: 'comment for node 1.2',
note: 'note for node 1.2',
name: 'node 1.2',
good: true,
},
{
description: 'description for node 1.3',
comment: 'comment for node 1.3',
note: 'note for node 1.3',
name: 'node 1.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 2',
comment: 'comment for node 2',
note: 'note for node 2',
name: 'node 2',
good: true,
children: [
{
description: 'description for node 2.1',
comment: 'comment for node 2.1',
note: 'note for node 2.1',
name: 'node 2.1',
bad: false,
},
{
description: 'description for node 2.2',
comment: 'comment for node 2.2',
note: 'note for node 2.2',
name: 'node 2.2',
good: true,
},
{
description: 'description for node 2.3',
comment: 'comment for node 2.3',
note: 'note for node 2.3',
name: 'node 2.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 3',
comment: 'comment for node 3',
note: 'note for node 3',
name: 'node 3',
bad: true,
good: false,
children: [
{
description: 'description for node 3.1',
comment: 'comment for node 3.1',
note: 'note for node 3.1',
name: 'node 3.1',
bad: false,
},
{
description: 'description for node 3.2',
comment: 'comment for node 3.2',
note: 'note for node 3.2',
name: 'node 3.2',
good: true,
},
{
description: 'description for node 3.3',
comment: 'comment for node 3.3',
note: 'note for node 3.3',
name: 'node 3.3',
bad: true,
good: false,
},
],
},
];
function displayField(val, key, parent, context) {
if (_.isArray(parent)) {
key = '[' + key + ']';
}
console.log(
_.repeat(' ', context.depth) +
'→ ' +
key +
': ' +
(_.isArray(val)
? '[' + val.length + ']'
: _.isObject(val)
? '{' + (val.name || '') + '}'
: val)
);
}
console.log('\n = Iterate over tree (each child object) = \n');
_.eachDeep(children, displayField, { childrenPath: 'children' });
console.log('\n = Iterate over object (each field) = \n');
_.eachDeep(children, displayField);
= Iterate over tree (each child object) =
→ [0]: {node 1}
→ [0]: {node 1.1}
→ [1]: {node 1.2}
→ [2]: {node 1.3}
→ [1]: {node 2}
→ [0]: {node 2.1}
→ [1]: {node 2.2}
→ [2]: {node 2.3}
→ [2]: {node 3}
→ [0]: {node 3.1}
→ [1]: {node 3.2}
→ [2]: {node 3.3}
= Iterate over object (each field) =
→ [0]: {node 1}
→ description: description for node 1
→ comment: comment for node 1
→ note: note for node 1
→ name: node 1
→ bad: false
→ children: [3]
→ [0]: {node 1.1}
→ description: description for node 1.1
→ comment: comment for node 1.1
→ note: note for node 1.1
→ name: node 1.1
→ bad: false
→ [1]: {node 1.2}
→ description: description for node 1.2
→ comment: comment for node 1.2
→ note: note for node 1.2
→ name: node 1.2
→ good: true
→ [2]: {node 1.3}
→ description: description for node 1.3
→ comment: comment for node 1.3
→ note: note for node 1.3
→ name: node 1.3
→ bad: true
→ good: false
→ [1]: {node 2}
→ description: description for node 2
→ comment: comment for node 2
→ note: note for node 2
→ name: node 2
→ good: true
→ children: [3]
→ [0]: {node 2.1}
→ description: description for node 2.1
→ comment: comment for node 2.1
→ note: note for node 2.1
→ name: node 2.1
→ bad: false
→ [1]: {node 2.2}
→ description: description for node 2.2
→ comment: comment for node 2.2
→ note: note for node 2.2
→ name: node 2.2
→ good: true
→ [2]: {node 2.3}
→ description: description for node 2.3
→ comment: comment for node 2.3
→ note: note for node 2.3
→ name: node 2.3
→ bad: true
→ good: false
→ [2]: {node 3}
→ description: description for node 3
→ comment: comment for node 3
→ note: note for node 3
→ name: node 3
→ bad: true
→ good: false
→ children: [3]
→ [0]: {node 3.1}
→ description: description for node 3.1
→ comment: comment for node 3.1
→ note: note for node 3.1
→ name: node 3.1
→ bad: false
→ [1]: {node 3.2}
→ description: description for node 3.2
→ comment: comment for node 3.2
→ note: note for node 3.2
→ name: node 3.2
→ good: true
→ [2]: {node 3.3}
→ description: description for node 3.3
→ comment: comment for node 3.3
→ note: note for node 3.3
→ name: node 3.3
→ bad: true
→ good: false
› deep filter object 📚 see docs
let children = [
{
description: 'description for node 1',
comment: 'comment for node 1',
note: 'note for node 1',
name: 'node 1',
bad: false,
children: [
{
description: 'description for node 1.1',
comment: 'comment for node 1.1',
note: 'note for node 1.1',
name: 'node 1.1',
bad: false,
},
{
description: 'description for node 1.2',
comment: 'comment for node 1.2',
note: 'note for node 1.2',
name: 'node 1.2',
good: true,
},
{
description: 'description for node 1.3',
comment: 'comment for node 1.3',
note: 'note for node 1.3',
name: 'node 1.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 2',
comment: 'comment for node 2',
note: 'note for node 2',
name: 'node 2',
good: true,
children: [
{
description: 'description for node 2.1',
comment: 'comment for node 2.1',
note: 'note for node 2.1',
name: 'node 2.1',
bad: false,
},
{
description: 'description for node 2.2',
comment: 'comment for node 2.2',
note: 'note for node 2.2',
name: 'node 2.2',
good: true,
},
{
description: 'description for node 2.3',
comment: 'comment for node 2.3',
note: 'note for node 2.3',
name: 'node 2.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 3',
comment: 'comment for node 3',
note: 'note for node 3',
name: 'node 3',
bad: true,
good: false,
children: [
{
description: 'description for node 3.1',
comment: 'comment for node 3.1',
note: 'note for node 3.1',
name: 'node 3.1',
bad: false,
},
{
description: 'description for node 3.2',
comment: 'comment for node 3.2',
note: 'note for node 3.2',
name: 'node 3.2',
good: true,
},
{
description: 'description for node 3.3',
comment: 'comment for node 3.3',
note: 'note for node 3.3',
name: 'node 3.3',
bad: true,
good: false,
},
],
},
];
console.log('\n = Filter tree (good children) = \n');
console.log(
_.filterDeep(children, 'good', { childrenPath: 'children' })
);
console.log('\n = Filter object (names of good children) = \n');
console.log(
_.filterDeep(children, (val, key, parent) => {
if (key == 'name' && parent.good) return true;
})
);
= Filter tree (good children) =
[
{
"description": "description for node 1",
"comment": "comment for node 1",
"note": "note for node 1",
"name": "node 1",
"bad": false,
"children": [
{
"description": "description for node 1.2",
"comment": "comment for node 1.2",
"note": "note for node 1.2",
"name": "node 1.2",
"good": true
}
]
},
{
"description": "description for node 2",
"comment": "comment for node 2",
"note": "note for node 2",
"name": "node 2",
"good": true,
"children": [
{
"description": "description for node 2.2",
"comment": "comment for node 2.2",
"note": "note for node 2.2",
"name": "node 2.2",
"good": true
}
]
},
{
"description": "description for node 3",
"comment": "comment for node 3",
"note": "note for node 3",
"name": "node 3",
"bad": true,
"good": false,
"children": [
{
"description": "description for node 3.2",
"comment": "comment for node 3.2",
"note": "note for node 3.2",
"name": "node 3.2",
"good": true
}
]
}
]
= Filter object (names of good children) =
[
{
"children": [
{
"name": "node 1.2"
}
]
},
{
"name": "node 2",
"children": [
{
"name": "node 2.2"
}
]
},
{
"children": [
{
"name": "node 3.2"
}
]
}
]
› find first matching deep meta-value 📚 see docs
// next time
// sorry
❤️
› find first matching deep value 📚 see docs
// next time
// sorry
❤️
› find the path of the first matching deep value 📚 see docs
// next time
// sorry
❤️
› get array of values processed by iteratee. 📚 see docs
let res = _.mapDeep(
{ hello: { from: { the: 'deep world', and: 'deepdash' } } },
(v) => v.toUpperCase(),
{ leavesOnly: true }
);
// res -> ['DEEP WORLD','DEEPDASH']
› get the object with same structure, but transformed values. 📚 see docs
let res = _.mapValuesDeep(
{ hello: { from: { the: 'deep world' } } },
(v) => v.toUpperCase(),
{ leavesOnly: true }
);
// res -> { hello: { from: { the: 'DEEP WORLD' } } }
› get the object with same values, but transformed keys. 📚 see docs
let res = _.mapKeysDeep(
{ hello: { from: { the: 'deep world' } } },
(v, k) => k.toUpperCase()
);
// res -> { HELLO: { FROM: { THE: 'deep world' } } }
› like reduce, but deep 📚 see docs
let max = _.reduceDeep({ a: 2, b: 3, c: { d: 6, e: [1, 5, 8] } },
(acc, value, key, parent, ctx) => {
if (typeof value == 'number' && (typeof acc != 'number' || value > acc))
return value;
return undefined;
}
);
// max == 8
› returns true if some matching deep value found 📚 see docs
// next time
// sorry
❤️
› pick values by paths specified by endings or regexes 📚 see docs
let children = [
{
description: 'description for node 1',
comment: 'comment for node 1',
note: 'note for node 1',
name: 'node 1',
bad: false,
children: [
{
description: 'description for node 1.1',
comment: 'comment for node 1.1',
note: 'note for node 1.1',
name: 'node 1.1',
bad: false,
},
{
description: 'description for node 1.2',
comment: 'comment for node 1.2',
note: 'note for node 1.2',
name: 'node 1.2',
good: true,
},
{
description: 'description for node 1.3',
comment: 'comment for node 1.3',
note: 'note for node 1.3',
name: 'node 1.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 2',
comment: 'comment for node 2',
note: 'note for node 2',
name: 'node 2',
good: true,
children: [
{
description: 'description for node 2.1',
comment: 'comment for node 2.1',
note: 'note for node 2.1',
name: 'node 2.1',
bad: false,
},
{
description: 'description for node 2.2',
comment: 'comment for node 2.2',
note: 'note for node 2.2',
name: 'node 2.2',
good: true,
},
{
description: 'description for node 2.3',
comment: 'comment for node 2.3',
note: 'note for node 2.3',
name: 'node 2.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 3',
comment: 'comment for node 3',
note: 'note for node 3',
name: 'node 3',
bad: true,
good: false,
children: [
{
description: 'description for node 3.1',
comment: 'comment for node 3.1',
note: 'note for node 3.1',
name: 'node 3.1',
bad: false,
},
{
description: 'description for node 3.2',
comment: 'comment for node 3.2',
note: 'note for node 3.2',
name: 'node 3.2',
good: true,
},
{
description: 'description for node 3.3',
comment: 'comment for node 3.3',
note: 'note for node 3.3',
name: 'node 3.3',
bad: true,
good: false,
},
],
},
];
console.log('\n = Pick name and description only = \n');
console.log(
_.pickDeep(children, ['name', 'description'])
);
= Pick name and description only =
[
{
"description": "description for node 1",
"name": "node 1",
"children": [
{
"description": "description for node 1.1",
"name": "node 1.1"
},
{
"description": "description for node 1.2",
"name": "node 1.2"
},
{
"description": "description for node 1.3",
"name": "node 1.3"
}
]
},
{
"description": "description for node 2",
"name": "node 2",
"children": [
{
"description": "description for node 2.1",
"name": "node 2.1"
},
{
"description": "description for node 2.2",
"name": "node 2.2"
},
{
"description": "description for node 2.3",
"name": "node 2.3"
}
]
},
{
"description": "description for node 3",
"name": "node 3",
"children": [
{
"description": "description for node 3.1",
"name": "node 3.1"
},
{
"description": "description for node 3.2",
"name": "node 3.2"
},
{
"description": "description for node 3.3",
"name": "node 3.3"
}
]
}
]
› get object without paths specified by endings or regexes 📚 see docs
let children = [
{
description: 'description for node 1',
comment: 'comment for node 1',
note: 'note for node 1',
name: 'node 1',
bad: false,
children: [
{
description: 'description for node 1.1',
comment: 'comment for node 1.1',
note: 'note for node 1.1',
name: 'node 1.1',
bad: false,
},
{
description: 'description for node 1.2',
comment: 'comment for node 1.2',
note: 'note for node 1.2',
name: 'node 1.2',
good: true,
},
{
description: 'description for node 1.3',
comment: 'comment for node 1.3',
note: 'note for node 1.3',
name: 'node 1.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 2',
comment: 'comment for node 2',
note: 'note for node 2',
name: 'node 2',
good: true,
children: [
{
description: 'description for node 2.1',
comment: 'comment for node 2.1',
note: 'note for node 2.1',
name: 'node 2.1',
bad: false,
},
{
description: 'description for node 2.2',
comment: 'comment for node 2.2',
note: 'note for node 2.2',
name: 'node 2.2',
good: true,
},
{
description: 'description for node 2.3',
comment: 'comment for node 2.3',
note: 'note for node 2.3',
name: 'node 2.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 3',
comment: 'comment for node 3',
note: 'note for node 3',
name: 'node 3',
bad: true,
good: false,
children: [
{
description: 'description for node 3.1',
comment: 'comment for node 3.1',
note: 'note for node 3.1',
name: 'node 3.1',
bad: false,
},
{
description: 'description for node 3.2',
comment: 'comment for node 3.2',
note: 'note for node 3.2',
name: 'node 3.2',
good: true,
},
{
description: 'description for node 3.3',
comment: 'comment for node 3.3',
note: 'note for node 3.3',
name: 'node 3.3',
bad: true,
good: false,
},
],
},
];
console.log('\n = Omit paths not ending with "e" = \n');
console.log(
_.omitDeep(children, /[^e]$/i, { onMatch: { skipChildren: false } }),
);
= Omit paths not ending with "e" =
[
{
"note": "note for node 1",
"name": "node 1",
"children": [
{
"note": "note for node 1.1",
"name": "node 1.1"
},
{
"note": "note for node 1.2",
"name": "node 1.2"
},
{
"note": "note for node 1.3",
"name": "node 1.3"
}
]
},
{
"note": "note for node 2",
"name": "node 2",
"children": [
{
"note": "note for node 2.1",
"name": "node 2.1"
},
{
"note": "note for node 2.2",
"name": "node 2.2"
},
{
"note": "note for node 2.3",
"name": "node 2.3"
}
]
},
{
"note": "note for node 3",
"name": "node 3",
"children": [
{
"note": "note for node 3.1",
"name": "node 3.1"
},
{
"note": "note for node 3.2",
"name": "node 3.2"
},
{
"note": "note for node 3.3",
"name": "node 3.3"
}
]
}
]
› get an object with all the paths as keys and corresponding values 📚 see docs
let index = _.index(
{
a: {
b: {
c: [1, 2, 3],
'hello world': {},
},
},
},
{ leavesOnly: true }
);
console.log(index);
Console:
{ 'a.b.c[0]': 1,
'a.b.c[1]': 2,
'a.b.c[2]': 3,
'a.b["hello world"]': {} }
› get an array of paths 📚 see docs
let paths = _.paths(
{
a: {
b: {
c: [1, 2, 3],
'hello world': {},
},
},
},
{ leavesOnly: false }
);
console.log(paths);
Console:
[ 'a',
'a.b',
'a.b.c',
'a.b.c[0]',
'a.b.c[1]',
'a.b.c[2]',
'a.b["hello world"]' ]
› condense sparse array 📚 see docs
let arr = ['a', 'b', 'c', 'd', 'e'];
delete arr[1];
console.log(arr);
delete arr[3];
console.log(arr);
_.condense(arr);
console.log(arr);
Console:
[ 'a', <1 empty item>, 'c', 'd', 'e' ]
[ 'a', <1 empty item>, 'c', <1 empty item>, 'e' ]
[ 'a', 'c', 'e' ]
› condense all the nested arrays 📚 see docs
let obj = { arr: ['a', 'b', { c: [1, , 2, , 3] }, 'd', 'e'] };
delete obj.arr[1];
delete obj.arr[3];
_.condenseDeep(obj);
console.log(obj);
Console:
{ arr: [ 'a', { c: [ 1, 2, 3 ] }, 'e' ] }
› like a _.has but returns false for empty array slots 📚 see docs
var obj = [, { a: [, 'b'] }];
console.log(_.exists(obj, 0)); // false
console.log(_.exists(obj, 1)); // true
console.log(_.exists(obj, '[1].a[0]')); // false
console.log(_.exists(obj, '[1].a[1]')); // true
› convert an array to string path (opposite to _.toPath) 📚 see docs
console.log(_.pathToString(['a', 'b', 'c', 'defg', 0, '1', 2.3]
,'prefix1', 'prefix2', '[3]'));
// prefix1.prefix2[3].a.b.c.defg[0][1]["2.3"]
console.log(_.pathToString(['"', '"', '"']));
// ["\\""]["\\""]["\\""]
console.log(_.pathToString('it.s.a.string'));
// it.s.a.string
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!