主题
flatMapDepth
js
_.flatMapDepth(collection, [iteratee=_.identity], [depth=1])
此方法与 _.flatMap
类似,不同之处在于它以递归方式展平映射结果,最多 depth
次。
¥This method is like _.flatMap
except that it recursively flattens the mapped results up to depth
times.
新增于
¥Since
4.7.0
参数
¥Arguments
collection
(数组|对象):要迭代的集合。¥
collection
(Array|Object): The collection to iterate over.[iteratee=_.identity]
(函数):每次迭代调用的函数。¥
[iteratee=_.identity]
(Function): The function invoked per iteration.[depth=1]
(数值):最大字符串长度。¥
[depth=1]
(number): The maximum recursion depth.
返回
¥Returns
(数组):返回新的扁平化数组。
¥(Array): Returns the new flattened array.
示例
¥Example
js
function duplicate(n) {
return [[[n, n]]];
}
_.flatMapDepth([1, 2], duplicate, 2);
// => [[1, 1], [2, 2]]