const myArr = [1, 2, 3, 4, 5, 6];
const newArr = myArr.flatMap(x => [x, x * 10]);
The flatMap()
method maps all array elements and creates a new flat array.
flatMap()
creates a new array from calling a function for every array element.
flatMap()
does not execute the function for empty elements.
flatMap()
does not change the original array.
array.flatMap(function(currentValue, index, arr), thisValue)
Parameters Parameter Description function() Required.undefined
.
this
value.
JavaScript Array flatMap()
is supported in all modern browsers since January 2020:
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4