hierarchy.iterateChildren ^v2.7.196
Iterates through the children of an element in a hierarchy.
js
hierarchy.iterateChildren(dimension, hierarchy, element, recursive)Parameters
| Parameter | Type | Description |
|---|---|---|
dimension | string | The dimension's name or id. |
hierarchy | string | The hierarchy's name or id. |
element | string | The parent element's name. Pass "" or null to iterate the hierarchy's top-level elements. |
recursive | boolean | Optional. true to include every descendant, or false for only the immediate children. Defaults to false. |
Returns
iterableAn iterable of child objects, to read with for...of. Each child has:
name(string): the element's name.fullName(string): the element's full name in the hierarchy.childIndex(number): the element's position under its parent, starting at0.childCount(number): how many immediate children the element has.depth(number): the element's depth in the iteration, when available.type(string):"N"for numeric or"S"for string.weight(number): the element's weight in its parent.
Iteration behaviour
hierarchy.iterateChildren returns an iterable view over the hierarchy rather than a pre-built array. Children are read as you loop, so it uses very little memory, even on large hierarchies.
Because it reads the hierarchy as you go, changing the hierarchy while you loop (adding, removing, reordering or rebuilding elements) can make it skip elements, repeat them or return them in an unexpected order.
If you need a stable snapshot, copy the children into an array first, using the spread operator ... or Array.from(). This uses more memory, but later changes to the hierarchy won't affect your copy.
Examples
js
const children = hierarchy.iterateChildren("Time", "Default", "2026", true);
for (const child of children) {
console.log(child);
}Example child object:
js
{
"name": "2026 - Q1",
"fullName": "Default»2026 - Q1",
"childCount": 3,
"childIndex": 0,
"depth": 0,
"type": "N",
"weight": 1
}Using spread
js
const children = [
...hierarchy.iterateChildren("Time", "Default", "2026", true),
];Using Array.from
js
const children = Array.from(
hierarchy.iterateChildren("Time", "Default", "2026", true),
);