Lodash – flatten Depth method

  • Post author:
  • Post category:Lodash
  • Post comments:1 Comment
Lodash - flatten Depth method

Syntax Of Lodash flatten Depth method

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

Lodash flatten Depth methods are 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 ]

Next Topic – Click Here

This Post Has One Comment

Leave a Reply