DEV Community

SATHISHKUMAR R
SATHISHKUMAR R

Posted on

What is foreach() in Javascript?

forEach() is an array method used to execute a function once for every element in an array.
(or)
forEach() is an array method that executes a callback function once for each element in an array.

Example:

let numbers = [10, 20, 30, 40, 50];

numbers.forEach(function(number) {
console.log(number);
});

Output:

10
20
30
40
50

Top comments (0)