Lodash - flattenDepth method



Syntax

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

Recursively flatten array up to depth times.

Arguments

  • array (Array) − The array to flatten.

  • [depth=1] (number) − The maximum recursion depth.

Output

  • (Array) − Returns the new flattened array.

Example

var _ = require('lodash');
var list = [1, [2], [4], 5, [[6]]];
var result = _.flattenDepth(list,2)

console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 1, 2, 4, 5, 6 ]
lodash_array.htm
Advertisements