-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
demo.js
58 lines (56 loc) · 1.29 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
//inject new method into lodash object
const _ = require('./dist/cjs/deepdash')(require('lodash'));
//in browser just load script after lodash
//<script src="lodash.js"></script>
//<script src="deepdash.js"></script>
let obj = {
a: {
b: {
c: {
d: [
{ i: 0 },
{ i: 1 },
{ i: 2 },
{ i: 3 },
{ i: 4 },
{ i: 5 },
{
o: {
d: new Date(),
f: function() {},
skip: {
please: {
dont: {
go: {
here: 'skip it',
},
},
},
},
},
},
],
s: 'hello',
},
b: true,
},
n: 12345,
u: undefined,
},
nl: null,
};
_.eachDeep(obj, (value, key, parent, ctx) => {
console.log(
_.repeat(' ', ctx.depth) +
key +
':' +
(value === null ? 'null' : typeof value),
ctx.parent.path && ' @' + ctx.parent.path
);
if (key == 'skip') {
return false; //return false explicitly to skip iteration over current value's children
}
});
// Chaining works too
// _(obj).eachDeep((value, key, path, depth, parent, parentKey, parentPath) => {/* do */}).value();