_.flattenDepth

_.flattenDepth(array, [depth=1])

Recursively flatten array up to depth times.

Since

4.4.0

Arguments

  1. array (Array): The array to flatten.
  2. [depth=1] (number): The maximum recursion depth.

Returns

(Array): Returns the new flattened array.

Example

var array = [1, [2, [3, [4]], 5]];
 
_.flattenDepth(array, 1);
// => [1, 2, [3, [4]], 5]
 
_.flattenDepth(array, 2);
// => [1, 2, 3, [4], 5]
doc_Lodash
2016-11-27 16:37:09
Comments
Leave a Comment

Please login to continue.