主题
flatMap
js
_.flatMap(collection, [iteratee=_.identity])
通过运行 collection
到 iteratee
中的每个元素并展平映射结果来创建一个展平的值数组。迭代器使用三个参数调用:(value, index|key, collection)。
¥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).
新增于
¥Since
4.0.0
参数
¥Arguments
collection
(数组|对象):要迭代的集合。¥
collection
(Array|Object): The collection to iterate over.[iteratee=_.identity]
(函数):每次迭代调用的函数。¥
[iteratee=_.identity]
(Function): The function invoked per iteration.
返回
¥Returns
(数组):返回新的扁平化数组。
¥(Array): Returns the new flattened array.
示例
¥Example
js
function duplicate(n) {
return [n, n];
}
_.flatMap([1, 2], duplicate);
// => [1, 1, 2, 2]