TypedArray map() JavaScript

The Javascript TypedArray map() method forms a new array with the result of calling a function for every element.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
array.map(function(value, index, arr), thisValue)
array.map(function(value, index, arr), thisValue)
array.map(function(value, index, arr), thisValue)

Parameters:
value: It represents the current element’s value.
index: It represents the index position of the current element.
arr: It represents the array on which map() is called.
thisValue: It represents this argument for the function.

Returns:
New Array.

Example 1:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
var gems =Jewels.map(function(Jewels)
{ return Jewels + " Jewellery "; });
document.write(gems);
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script type="text/javascript"> var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"]; var gems =Jewels.map(function(Jewels) { return Jewels + " Jewellery "; }); document.write(gems); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">   
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
var gems =Jewels.map(function(Jewels)  
{  return Jewels + " Jewellery ";  });    
document.write(gems);  
</script>
</body>
</html>

Example 2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
const testArray = new Uint8Array([100, 36]);
const roots = testArray.map(Math.sqrt);
document.write(roots);
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script type="text/javascript"> const testArray = new Uint8Array([100, 36]); const roots = testArray.map(Math.sqrt); document.write(roots); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript"> 
const testArray = new Uint8Array([100, 36]);
const roots = testArray.map(Math.sqrt);
 
document.write(roots);
 
</script>
</body>
</html>