
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
Pingback: Lodash - flattens Deep methods - Adglob Infosystem Pvt Ltd