const colours = [ { r: 1, g: 0, b: 0 }, { r: 0, g: 1, b: 0 }, { r: 0, g: 0, b: 1 } ];
// Children:
// [
// { name: "array[0]", value: {r:1,g:0,b:0} },
// { name: "array[1]", value: {r:0,g:1,b:0} },
// { name: "array[2]", value: {r:0,g:0,b:1} },
// ]
Pass in options.name
(eg 'colours') to have names generated as 'colours[0]', etc.
Options can also be used to filter children. By default all direct children are returned.
Yields the direct (ie. non-recursive) children of a tree-like object as a pairing of node name and value. Supports basic objects, Maps and arrays.
To iterate recursively, consider depthFirst
Each child is returned in an TraverseObjectEntry structure:
For example, iterating over a flat object:
For objects containing objects:
Note that 'sourceValue' always contains the property value, as if you access it via
object[propName]
. 'leafValue' only contains the value if it's a leaf node.Arrays are assigned a name based on index.