Function flatMap

  • Creates a flattened array of values by running each element in collection thru iteratee and flattening the mapped results. The iteratee is invoked with three arguments: (value, index|key, collection).

    Type Parameters

    • T

    • R = any

    Parameters

    • collection: T[]

      The collection to iterate over.

    • Optional iteratee: ArrayIteratee<T, T[]>

      The function invoked per iteration.

      Optional

    Returns R[]

    Returns the new flattened array.

    Since

    5.4.0

    See

    [[flatMapDeep]],[[flatMapDepth]],[[flatten]],[[flattenDeep]],[[flattenDepth]],[[map]],[[mapKeys]],[[mapValues]]

    Example

    function duplicate(n) {
    return [n, n]
    }

    flatMap([1, 2], duplicate)
    // => [1, 1, 2, 2]
  • Type Parameters

    • T

    • R = any

    Parameters

    • collection: Record<string, T>
    • Optional iteratee: RecordIteratee<T, Record<string, T>>
      Optional

    Returns R[]