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

    const obj = { foo: { bar: [1] } };
    const value = getNumber(obj, 'foo.bar[0]');
    // type of value -> number; value -> 1

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    Returns Nullable<number>

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

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

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    • defaultValue: number

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

    Returns number