Skip to content

traverse

Recursively visit each property of an object (or each element of an array) and its nested objects or arrays. By default, the only nested objects to be traversed are plain objects and arrays.

Usage

const root = { a: 1, b: { c: { d: [2] }, e: 3 } };
traverse(root, (value, key, parent, context) => {
console.log(key, "=>", value);
});
// Logs the following:
// a => 1
// b => { … }
// c => { … }
// d => [ 2 ]
// 0 => 2
// e => 3

Installation

Terminal window
npx atmx add helper traverse