Function filterMap

  • This is like calling input.map(transform).filter(item => item !=== undefined). But if I used that line typescript would get the output type wrong. Array.prototype.flatMap() is a standard and traditional alternative.

    Type Parameters

    • Input
    • Output

    Parameters

    • input: Input[]

      The values to be handed to transform() one at a time.

    • transform: ((input: Input, index: number) => undefined | Output)

      The function to be called on each input. index is the index of the current input, just like in Array.prototype.forEach().

        • (input, index): undefined | Output
        • Parameters

          • input: Input
          • index: number

          Returns undefined | Output

    Returns Output[]

    The items returned by transform(), with any undefined items removed.