Skip to content

Instantly share code, notes, and snippets.

@shisama
Created April 23, 2019 17:26
Show Gist options
  • Save shisama/bbb9601cf1fdd572e19f234b5a1d7e4a to your computer and use it in GitHub Desktop.
Save shisama/bbb9601cf1fdd572e19f234b5a1d7e4a to your computer and use it in GitHub Desktop.
Array.prototype.flatMap - New JavaScript Features in Node.js v12
var arr1 = [1, 2, 3, 4];
arr1.map(x => [x * 2]);
// [[2], [4], [6], [8]]
arr1.flatMap(x => [x * 2]);
// [2, 4, 6, 8]
// only one level is flattened
arr1.flatMap(x => [[x * 2]]);
// [[2], [4], [6], [8]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment