Function map

  • Creates an array of values by running each element in collection thru iteratee. The iteratee is invoked with three arguments: (value, index|key, collection).

    Many lodash methods are guarded to work as iteratee for methods like every, filter, map, mapValues, reject, and some.

    The guarded methods are: ary, chunk, curry, curryRight, drop, dropRight, every, fill, invert, parseInt, random, range, rangeRight, repeat, sampleSize, slice, some, sortBy, split, take, takeRight, template, trim, trimEnd, trimStart, and words

    Type Parameters

    • T extends any[] | []

    Parameters

    • collection: T

    Returns Tuple<T>

    Since

    5.0.0

    Example

    function square(n) {
    return n * n;
    }

    map([4, 8], square);
    // => [16, 64]

    map({ 'a': 4, 'b': 8 }, square);
    // => [16, 64] (iteration order is not guaranteed)

    var users = [
    { 'user': 'barney' },
    { 'user': 'fred' }
    ];

    map(users, 'user');
    // => ['barney', 'fred']
  • Type Parameters

    • T

    • R = any

    Parameters

    • collection: ArrayLike<T>
    • Optional iteratee: ArrayIteratee<T, R>
      Optional

    Returns R[]

  • Type Parameters

    • T

    • R = any

    Parameters

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

    Returns R[]

  • Parameters

    • collection: any
    • Optional iteratee: any
      Optional

    Returns []