flattenDepth

Array
since 4.4.0

Arguments

  • Array The array to flatten.
  • number The maximum recursion depth.

Returns

Array the new flattened array.

Recursively flatten array up to depth times.

Example of Lodash _.flattenDepth

var array = [1, [2, [3, [4]], 5]];

_.flattenDepth(array, 1);
// => [1, 2, [3, [4]], 5]

_.flattenDepth(array, 2);
// => [1, 2, 3, [4], 5]