JavaScript Iterator map()
Example
Return a new array with the square root of all element values:
// Create an iterator
const myIterator = Iterator.from("123456789");
// Map the Iterator
const mappedIterator = myIterator.map(x => x * 2);
Try it Yourself »
const myIterator = Iterator.from("123456789");
// Map the Iterator
const mappedIterator = myIterator.map(x => x * 2);
Description
map()
creates a new iterator from calling a
function for every iterator element.
map()
does not execute the function for empty elements.
map()
does not change the original iterator.
Syntax
iterator.map(function(currentValue, index, arr), thisValue)
Parameters
Parameter
Description
function()
Required.
A function to be run for each iterator element.
A function to be run for each iterator element.
currentValue
Required.
The value of the current element.
The value of the current element.
index
Optional.
The index of the current element.
The index of the current element.
arr
Optional.
The array of the current element.
The array of the current element.
thisValue
Optional.
Default value
A value passed to the function to be used as its
Default value
undefined
.A value passed to the function to be used as its
this
value.Return Value
Type
Description
An iterator The results of running a function for each iterator element.
Browser Support
iterator.map()
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 |