JavaScript: Array.prototype.flatMap

By Xah Lee. Date: . Last updated: .

New in JS2019.

arrayX.flatMap(f)
Apply function to every element of the array then flatten 1 level. Return the new array. Original array is not changed.
The function f is passed 3 args: • current_elementcurrent_indexarrayX.
arrayX.flatMap(f, thisArg)
Use thisArg for this Binding of f. If it is not given, undefined is used.
const a1 = [[1,2],[[3],4]];
const a2 = a1.flatMap( (x => x[0]) );
console.log(a2);
// [ 1, 3 ]
JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype