DEV Community

Discussion on: ES2019 new features

Collapse
 
paullouismas profile image
Paul-Louis

In Array.prototype.flatMap, Javascript performs the .map before the .flat .

This means that the result of

var array = [1, 23, [10, 43]];
console.log(array.flatMap(item => item + 2));

Should be [3, 25, "10,432"] instead of [3, 25, 12, 45]

as

var array = [1, 23, [10, 43]];
console.log(array.flatMap(item => item + 2));

is equivalent to

var array = [1, 23, [10, 43]];
console.log(array.map(item => item + 2).flat(1));