Monster.Types. NodeRecursiveIterator

You can create the instance via the monster namespace new Monster.Types.NodeRecursiveIterator().

Constructor

new NodeRecursiveIterator(dataopt)

An iterator to run recursively through a tree of nodes

Parameters:
NameTypeAttributesDescription
dataNode<optional>
Since
  • 1.26.0
License
  • AGPLv3
Example
import {Node} from '@schukai/monster/source/types/node.mjs';
import {NodeRecursiveIterator} from '@schukai/monster/source/types/noderecursiveiterator.mjs';

const node = new Node('1')

// 1
// 2
// ├ 2.1
// ├ 2.2
// └ 2.3
// 3
// 4
// ├ 4.1
// └ 4.2
node.appendChild(
        (new Node('2'))
            .appendChild(new Node('2.1'))
            .appendChild(new Node('2.2'))
            .appendChild(new Node('2.3')))
    .appendChild(new Node('3'))
    .appendChild(new Node('4')
        .appendChild(new Node('4.1'))
        .appendChild(new Node('4.2')));

const iterator = new NodeRecursiveIterator(node);

const result = [];
for (const n of iterator) {
    result.push(n.value);
}

// ↦ ['1', '2', '2.1', '2.2', '2.3', '3', '4', '4.1', '4.2']

Methods

forEach(callback) → {Monster.Types.NodeRecursiveIterator}

Parameters:
NameTypeDescription
callbackfunction