JavaScript

Explain flatMap() array method

Medium
2
Added
First maps each element, then flattens result by 1 level. Combines map() and flat().

Solution Code

JavaScript
[1,2,3].flatMap(x => [x, x*2]); // [1,2,2,4,3,6]
Explanation
More efficient than separate map+flat operations. Handles sparse arrays.

Guided Hints

Depth control
Use cases