const array = [1, [2, [3, 4, [5, 6]]], 7];
console.log(array.flat(1)); // [ 1, 2, [ 3, 4, [ 5, 6 ] ], 7 ]
console.log(array.flat(2)); // [ 1, 2, 3, 4, [ 5, 6 ], 7 ]
console.log(array.flat(3)); // [ 1, 2, 3, 4, 5, 6, 7 ]
.flat()
(ES2019) will flatten an array up to the given depth level.
Thanks for reading π
Follow @codedrops.tech for daily posts.
Instagram β Twitter β Facebook
Micro-Learning β Web Development β Javascript β MERN stack β Javascript
codedrops.tech
Top comments (0)