CodesJava

Easy learning with example program codes

TypedArray forEach() JavaScript

The Javascript TypedArray forEach() method is used to call a specified function once for each element of the array.

Syntax:

array.forEach(function(value, index, array), thisValue)  

Parameters:
value: It represents the current element’s value.
index: It represents the index position of current element.
array: It represents the array.
thisValue: It represents this argument for the function.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">  
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];  
Jewels.forEach(function(i)  
{   document.write(i+"<br/>")});  
</script>
</body>
</html>

Output:

DIAMOND
GOLD
PLATINUM
SILVER

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">  
function logArrayElements(element, index, array) {
  document.write('arr[' + index + '] = ' + element);
  document.write("</br>");
}
 
new Uint8Array([30, 15, 42, 23]).forEach(logArrayElements);
 
</script>
</body>
</html>

Output:

arr[0] = 30
arr[1] = 15
arr[2] = 42
arr[3] = 23
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status