4.17.11
3.10.1
2.4.2
1.3.1
_.map(collection, [iteratee=_.identity])
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 iteratees 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
Since
0.1.0
Arguments
argument
collection[iteratee=_.identity]type
(Array|Object)
Function
description
The collection to iterate over.
The function invoked per iteration.
Returns
(array)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" },
];
// The `_.property` iteratee shorthand.
_.map(users, "user");
// => ['barney', 'fred']
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" }];
// The `_.property` iteratee shorthand.
_.map(users, "user");
// => ['barney', 'fred']