• Given a deep-search query path, returns an object property or array value of an object or array as an AnyArray, or undefined if a value was not found or was not type-compatible.

    const obj = { foo: { bar: [1, 2, 3] } };
    const value = getArray(obj, 'foo.bar');
    // type of value -> AnyArray; value -> [1, 2, 3]

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    Returns Nullable<AnyArray>

  • Given a deep-search query path, returns an object property or array value of an object or array as an AnyArray, or undefined if a value was not found or was not type-compatible.

    const obj = { foo: { bar: [1, 2, 3] } };
    const value = getArray(obj, 'foo.baz', [4, 5, 6]);
    // type of value -> AnyArray; value -> [4, 5, 6]

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    • defaultValue: AnyArray

      The default to return if the query result was not defined.

    Returns AnyArray