ml318097

Mehul Lakhanpal

Posted on December 29, 2020

Array.flat()
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 ]
Enter fullscreen mode Exit fullscreen mode

.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

πŸ’– πŸ’ͺ πŸ™… 🚩
ml318097
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