Typed Array map()
Examples
Return a new array with the square root of all element values:
// Create a Typed Array
const myArr = Int16Array.from([4, 9, 16, 25]);
// Create a new Typed Array
const newArr = myArr.map(Math.sqrt);
Try it Yourself »
Multiply all the values in an array with 10:
const numbers = [65, 44, 12, 4];
const newArr = numbers.map(myFunction)
function myFunction(num) {
return num * 10;
}
Try it Yourself »
Description
map()
creates a new array from calling a
function for every array element.
map()
does not execute the function for empty elements.
map()
does not change the original array.
Typed Array Iteration Methods:
Syntax
array.map(function(currentValue, index, arr), thisValue)
Parameters
Parameter | Description |
function() | Required. A function to be run for each array element. |
currentValue | Required. The value of the current element. |
index | Optional. The index of the current element. |
arr | Optional. The array 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 |
An array | The results of a function for each array element. |
JavaScript Typed Arrays
Browser Support
typed-array.map()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is fully supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |