Function dataGet

  • Utility to safely access values on a deeply nested structure. If path doesn't exist, return the default value.


    const result1 = dataGet([{key:{prop:1}}], '0.key.prop') // 1;
    const result2 = dataGet([{key:{prop:1}}], '*.key.prop') // [1];

    Type Parameters

    • T


    • data: undefined | Collection<Record<string, any>> | MaybeArray<Record<string, any>> = undefined

      the structure to search.

    • path: MaybeArray<string> | Collection<string>

      the path to the value delimited by '.'

    • Optional defaultValue: T

      the value to return if the path doesn't exist.

    Returns T | undefined

Generated using TypeDoc