javascript
how to merge two dimensional array into one dimensional
const a = [[0,1,2,3,4],[5,6,7,8]];
const flattenedArray = a.flat().sort((a, b) => a - b);
console.log(flattenedArray);
Output
[0, 1, 2, 3, 4, 5, 6, 7, 8]
Was this helpful?
Similar Posts
- Combine or merge two or multiple arrays into single array in Javascript
- Merge multiple arrays and strings into single array using Lodash
- Concatenate multiple objects into one using Javascript
- Lodash - merge two arrays and remove duplicates from it
- Break an array into fixed length array groups using lodash in Javascript
- Lodash - Get all elements of array except the last one
- Javascript to split string into array of characters