HomeLanguagesJavascriptJavaScript typedArray.map() Method

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




// Creating a typedArray with some elements
const A = new Uint8Array([4, 9, 16, 25, 36]);
  
// Calling map() function with the parameter
// Math.sqrt function which find square root 
// of the typedArray's elements
const B = A.map(Math.sqrt);
  
// Printing the result of the function
console.log(B);


Output:

2,3,4,5,6

Example 2: 

javascript




// Creating a typedArray with some elements
var A = new Uint8Array([1, 2, 3, 4, 5, 6]);
  
// Calling map() function
var B = A.map(function(a) {
    return a * 5;
});
  
// Returning the results
console.log(B);


Output:

5,10,15,20,25,30
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32713 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7088 POSTS0 COMMENTS
Nicole Veronica
12228 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12310 POSTS0 COMMENTS
Shaida Kate Naidoo
7203 POSTS0 COMMENTS
Ted Musemwa
7470 POSTS0 COMMENTS
Thapelo Manthata
7189 POSTS0 COMMENTS
Umr Jansen
7171 POSTS0 COMMENTS