This method is like flatMap except that it recursively flattens the mapped results up to depth times.
flatMap
depth
The function invoked per iteration.
Optional
The maximum recursion depth.
Returns the new flattened array.
4.7.0
flatMap, flatMapDeep, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues
function duplicate(n) { return [[[n, n]]]}flatMapDepth([1, 2], duplicate, 2)// => [[1, 1], [2, 2]] Copy
function duplicate(n) { return [[[n, n]]]}flatMapDepth([1, 2], duplicate, 2)// => [[1, 1], [2, 2]]
This method is like
flatMapexcept that it recursively flattens the mapped results up todepthtimes.