JavaScript Array forEach () Method
JavaScript Tutorial » JavaScript forEach()
The arr.forEach() method calls the provided function once for each element of the array.
Syntax:
Example:
array.forEach(function(currentValue, index, arr), thisValue)
Parameters: This method accepts five parameters:
- currentValue: Required. The value of the current element
- index: Optional. The array index of the current element
- arr: Optional. The array object the current element belongs to
- thisValue: Optional. A value to be passed to the function to be used as its "this" value.
JS foreach () array - example
In this example the method forEach() calculates multiplication of every element of the array.
Example:
Output:
Get multiplication of the numbers in the array.
1440
<!DOCTYPE html>
<html>
<body><p>Get multiplication of the numbers in the array.</p>
<p id="my_demo"></p>
<script>
var my_multiplication = 2;
var my_numbers = [3, 4, 6, 10];
my_numbers.forEach(my_Function);function my_Function(item) {
</body>
my_multiplication *= item;
document.getElementById("my_demo").innerHTML = my_multiplication;
}
</script>
</html>
Get multiplication of the numbers in the array.
1440
javascript foreach object, array, continue, break, return, example, key value, json, async, array of objects, element in array, loop, await
javascript foreach object, array, continue, break, return, example, key value, json, async, array of objects, element in array, loop, await
JavaScript Array forEach () Method - javascript tutorial
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.