Array.prototype.reduceRightintermediateconst nested = [[1, 2], [3, 4], [5]]
nested.reduceRight((acc, arr) => acc.concat(arr), [])
// β [5, 3, 4, 1, 2]Use reduceRight() to flatten nested arrays from right to left.
You can flatten a 2D array from right to left. To preserve the original element order, use cur.concat(acc) instead of acc.concat(cur).
[[1, 2], [3, 4]].reduceRight((acc, cur) => cur.concat(acc), []) // [1, 2, 3, 4]