CodesJava

Easy learning with example program codes

TypedArray map() JavaScript

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

Syntax:

array.map(function(value, index, arr), thisValue) 

Parameters:
value: It represents the current element’s value.
index: It represents the index position of 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:

<!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>

Output:

DIAMOND Jewellery ,GOLD Jewellery ,PLATINUM Jewellery ,SILVER Jewellery

Example 2:

<!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>

Output:

10,6
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status