JavaScript typedArray.map() Method
The typedArray.map() is an inbuilt function in JavaScript which is used to create a new typedArray with the result of a provided function on each element of the given typedArray.
Syntax:
typedArray.map(callback)
Parameters: It accepts a parameter callback function which accept some parameter which are specified below-
- currentValue: It is the current element which is being processed in the typedArray.
- index: It is the index of the current element which is being processed in the typedArray.
- array: It is the typedArray which is being called.
Return value: It returns a new typedArray with the result of a provided function on each element of the given typedArray.
Example 1:
javascript
const A = new Uint8Array([4, 9, 16, 25, 36]);
const B = A.map(Math.sqrt);
console.log(B);
|
Output:
2,3,4,5,6
Example 2:
javascript
var A = new Uint8Array([1, 2, 3, 4, 5, 6]);
var B = A.map( function (a) {
return a * 5;
});
console.log(B);
|
Output:
5,10,15,20,25,30
Last Updated :
10 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...