Function objWalk

  • Recursively traverses an object and invokes a callback function for every encountered non-object value. The callback function is passed the non-object value and an array representing the path to the value.

    Parameters

    • node: Record<string, any>

      The object to be traversed.

    • callback: ((value, path) => void)

      The callback function to be invoked for every non-object value.

        • (value, path): void
        • Parameters

          • value: any
          • path: string[]

          Returns void

    Returns void

    Example

    const obj = { a: 1, b: { c: 2, d: [3, 4] } };
    objWalk(obj, (value, path) => {
    console.log(`Path: ${path.join('.')}, Value: ${value}`);
    });
    // Output:
    // Path: a, Value: 1
    // Path: b.c, Value: 2
    // Path: b.d[0], Value: 3
    // Path: b.d[1], Value: 4

Generated using TypeDoc