Array.prototype.reduceintermediateconst nested = [[1, 2], [3, 4], [5]]
nested.reduce((acc, arr) => acc.concat(arr), [])
// β [1, 2, 3, 4, 5]Use reduce() to flatten one level of nested arrays by concatenating each sub-array.
You can flatten a 2D array using reduce() with concat().
[[1, 2], [3, 4]].reduce((acc, cur) => acc.concat(cur), []) // [1, 2, 3, 4]