Array.flat()
Mehul Lakhanpal
Posted on December 29, 2020
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
π πͺ π
π©
Mehul Lakhanpal
Posted on December 29, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript 5 Input Events That You Will Use At Least One Of Them In Your Next Projects.
August 5, 2021