• Maps the given iterable to a new array with the given transform function. The result of the transform function will only be included in the returned array, if and only if the result was strictly not equal to undefined or null.

    Thus, the returned array can never include undefined or null.

    Use this if you want to map and filter simultaneously; avoiding unnecessary loops.

    See

    mapNotUndefined

    Example

    const accounts = [{ id: 0, name: 'A' }, { id: 1, name: null }];
    const names: string[] = mapDefined(accounts, account => account.name);

    Type Parameters

    Type Parameters

    • T

      the type of the items in the iterable

    • U

      the type of the items in the returned array

    Parameters

    • iterable: Iterable<T>

      an iterable to transform

    • transform: ((value: T) => undefined | null | U)

      the transform function

        • (value: T): undefined | null | U
        • Parameters

          • value: T

          Returns undefined | null | U

    Returns U[]

Generated using TypeDoc