服务器

Array

Collection

Date

Function

Lang

Math

Number

Object

Seq

String

Util

Properties

Methods

_.map(collection, iteratee=_.identity)

通过运行iteratee中的每个元素来创建一个值的数组。 迭代器被调用三个参数:

(value, index|key, collection).

可以用许多lodash方法防护,iteratees工作如下:_.every_.filter_.map_.mapValues_.reject,和_.some

防护的方法是:

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

初始

0.1.0

参数
  1. collection (Array | Object):迭代的集合。
  2. [iteratee=_.identity] (Function):每次迭代调用的函数。
返回

(Array):返回新的映射数组。

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']