Created
April 23, 2019 17:26
-
-
Save shisama/bbb9601cf1fdd572e19f234b5a1d7e4a to your computer and use it in GitHub Desktop.
Array.prototype.flatMap - New JavaScript Features in Node.js v12
This file contains 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
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