javascript
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
Was this helpful?
Similar Posts
- Lodash - Flatten an array to multi levels deep
- Lodash - Flatten an array to a fixed depth
- Merge multiple arrays and strings into single array using Lodash
- Combine or merge two or multiple arrays into single array in Javascript
- Break an array into fixed length array groups using lodash in Javascript
- Get all values from an array which does not exist in other array Lodash
- Pass multiple arguments when calling a function which takes single argument Javascript