It iterates through a graph or a tree recursively.
- for support ES5 see
2.x.x
versions
let iterator = new RecursiveIterator(
root /* {Object|Array} */,
[bypassMode = 0] /* {Number} */,
[ignoreCircular = false] /* {Boolean} */,
[maxDeep = 100] /* {Number} */
)
let {value, done} = iterator.next()
let {parent, node, key, path, deep} = value
// parent is parent node
// node is current node
// key is key of node
// path is path to node
// deep is current deep
let root = {
object: {
number: 1
},
string: 'foo'
}
for (let {node, path} of new RecursiveIterator(root)) {
console.log(path.join('.'), node)
}
// object Object {number: 1}
// object.number 1
// string foo
- Syntax
- API
- Cookbook (es6)
bower install recursive-iterator
You could find this module in bower like recursive iterator.
npm install recursive-iterator
You could find this module in npm like recursive iterator.