Skip to content
Alex edited this page May 31, 2015 · 3 revisions

ES6

var root = {
    object: {
        number: 1
    },
    string: 'foo'
};

for(let item of new RecursiveIterator(root)) {
    console.log(item.path.join('.'), item.node);
}

// or

for(let {parent, node, key, path, deep} of new RecursiveIterator(root)) {
    console.log(path.join('.'), node);
}

// or

for(let {node, path} of new RecursiveIterator(root, 1)) {
    console.log(path.join('.'), node);
}

ES5

var root = {
    object: {
        number: 1
    },
    string: 'foo'
};

var iterator = new RecursiveIterator(root);
for(var item = iterator.next(); !item.done; item = iterator.next()) {
    var state = item.value;
    console.log(state.path.join('.'), state.node);
}
Clone this wiki locally