• Given a deep-search query path, returns an object property or array value of an object or array.

    const obj = { foo: { bar: ['baz'] } };
    const value = get(obj, 'foo.bar[0]');
    // type of value -> unknown; value === 'baz'

    const value = get(obj, 'foo.bar.nothing', 'default');
    // type of value -> unknown; value === 'default'

    const value = get(obj, 'foo["bar"][0]');
    // type of value -> unknown; value === 'baz'

    const arr = [obj];
    const value = get(arr, '[0].foo.bar[0]');
    // type of value -> unknown; value === 'baz'

    Parameters

    • from: unknown

      Any value to query.

    • path: string

      The query path.

    • OptionaldefaultValue: unknown

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

    Returns unknown