common-stuff
    Preparing search index...

    Function getByKey

    • Get object value by nested keys.

      When the path is a string literal ('a.b.c') or a tuple of literals (['a', 'b'] as const), the return type is inferred from T by walking the path. For dynamic paths (variable strings or non-tuple arrays) the return type is unknown; pass T explicitly via the first generic if you know what to expect.

      Type Parameters

      • T
      • const P extends string | readonly (string | number)[]

      Parameters

      • target: T
      • keys: P

      Returns GetByPath<T, P>

      getByKey({ a: [1, 2, { b: 'value' }] }, 'a.2.b')
      // 'value' — inferred as string

      getByKey({ a: [1, 2, { b: 'value' }] }, ['a', 2, 'b'] as const)
      // 'value' — inferred as string

      getByKey<number>(data, somePathVariable)
      // explicit fallback for dynamic paths
    • Get object value by nested keys.

      When the path is a string literal ('a.b.c') or a tuple of literals (['a', 'b'] as const), the return type is inferred from T by walking the path. For dynamic paths (variable strings or non-tuple arrays) the return type is unknown; pass T explicitly via the first generic if you know what to expect.

      Type Parameters

      • R = unknown

      Parameters

      • target: unknown
      • keys: string | (string | number)[]

      Returns R

      getByKey({ a: [1, 2, { b: 'value' }] }, 'a.2.b')
      // 'value' — inferred as string

      getByKey({ a: [1, 2, { b: 'value' }] }, ['a', 2, 'b'] as const)
      // 'value' — inferred as string

      getByKey<number>(data, somePathVariable)
      // explicit fallback for dynamic paths