Skip to content

Instantly share code, notes, and snippets.

@kutyel
Created August 2, 2019 08:00
Show Gist options
  • Save kutyel/3226d3692f4dadc97e2c5be349a7ebb6 to your computer and use it in GitHub Desktop.
Save kutyel/3226d3692f4dadc97e2c5be349a7ebb6 to your computer and use it in GitHub Desktop.
Array.prototype.flat()
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