JavaScript Iterator flatMap()
Example
// Create an Iterator
const myIterator = Iterator.from([1, 2, 3, 4, 5, 6]);
// Map the Iterator
const mappedIterator = myIterator.flatMap(x => [x, x * 10]);
Try it Yourself »
Description
The flatMap() method maps all iterator elements and creates a new flat iterator.
flatMap() creates a new iterator from calling a 
function for every array element.
flatMap() does not execute the function for empty elements.
flatMap() does not change the original iterator.
Syntax
iterator.flatMap(function(currentValue, index, arr), thisValue)
Parameters
| Parameter | Description | 
| function() | Required. A function to be run for each iterator element.  | 
  
| currentValue | Required. The value of the current element.  | 
  
| index | Optional. The index of the current element.  | 
  
| arr | Optional. The iterator of the current element.  | 
  
| thisValue | Optional. Default value undefined.A value passed to the function to be used as its this value. | 
  
Return Value
| Type | Description | 
| Iterator | An iterator with the elements as a result of a callback function and then flattened. | 
Browser Support
iterator.flatMap() is a JavaScript 2025 feature.
ES 2025 is fully supported in all modern browsers since May 2025:
| Chrome 136  | 
    Edge 136  | 
    Firefox 129  | 
    Safari 18.2  | 
    Opera 120  | 
  
| Apr 2025 | Apr 2025 | Aug 2024 | Des 2024 | May 2025 |