主题
flatMapDeep
js
_.flatMapDeep(collection, [iteratee=_.identity])
此方法与 _.flatMap
类似,不同之处在于它以递归方式展平映射结果。
¥This method is like _.flatMap
except that it recursively flattens the mapped results.
新增于
¥Since
4.7.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]]];
}
_.flatMapDeep([1, 2], duplicate);
// => [1, 1, 2, 2]