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]]);
// => [10,20,[33,[40]],50]
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

_.flatten Lodash


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?