Lodash - Flatten an array to single level deep

You can flatten an array to the first level then you can use the _.flatten method of lodash.

const arr = _.flatten([[10], [20, [33, [40]], 50]]);
// => [10,20,[33,[40]],50]

_.flatten Lodash


Parameters description

Array: [Required] The Array which you want to convert to 1 Dimensional Array on first level.

Example Demo

Was this helpful?