Create a new array with the sub-array elements concatenated:
const myArr = [[1,2],[3,4],[5,6]];
const newArr = myArr.flat();
const myArr = [1, 2, [3, [4, 5, 6], 7], 8];
const newArr = myArr.flat(2);
The flat()
method concatenates sub-array elements.
JavaScript Array flat()
is supported in all modern browsers since January 2020:
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4