Skip to content

Instantly share code, notes, and snippets.

@shisama
Last active April 23, 2019 17:27
Show Gist options
  • Save shisama/e1940e588b88b90e61c3984d7d691a9b to your computer and use it in GitHub Desktop.
Save shisama/e1940e588b88b90e61c3984d7d691a9b to your computer and use it in GitHub Desktop.
Array.prototype.flat - New JavaScript Features in Node.js v12
var arr1 = [1, 2, [3, 4]];
arr1.flat();
// [1, 2, 3, 4]
var arr2 = [1, 2, [3, 4, [5, 6]]];
arr2.flat();
// [1, 2, 3, 4, [5, 6]]
var arr3 = [1, 2, [3, 4, [5, 6]]];
arr3.flat(2);
// [1, 2, 3, 4, 5, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment