Search code snippets, questions, articles...

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]]);
console.log(arr);
// => [10,20,[33,[40]],50]

_.flatten Lodash

_.flatten(Array)

Parameters description

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

Example Demo

Search Index Data (The code snippet can also be found with below search text)

_.flatten lodash
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet