Created
August 2, 2019 08:00
-
-
Save kutyel/3226d3692f4dadc97e2c5be349a7ebb6 to your computer and use it in GitHub Desktop.
Array.prototype.flat()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1, 2, 3, [4, 5]] | |
arr.flat() // > [1, 2, 3, 4, 5] | |
const arr1 = [1, 2, [3, 4, [5, 6]]] | |
arr1.flat(2) // > [1, 2, 3, 4, 5, 6] | |
const arr2 = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]] | |
arr2.flat(Infinity) // > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
// Si tienes huecos vacíos en tu array también los limpiará! | |
const arr3 = [1, 2, , 4, 5] | |
arr3.flat() // > [1, 2, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment