codetrix - v1.5.0
    Preparing search index...

    Function getNested

    • Safely retrieves a nested value from an object using a path.

      Type Parameters

      • T = any

      Parameters

      • obj: any

        The object to query.

      • path: string

        The path to the nested property (dot-separated).

      • Optionalfallback: T

        The fallback value if the path doesn't exist.

      Returns T

      The value at the nested path or the fallback.

      getNested({ a: { b: 2 } }, 'a.b'); // 2
      getNested({ a: { b: 2 } }, 'a.c', 0); // 0