The forEach method in Javascript repeats the elements of an array and calls the provided function for each element in order.


The arr.forEach(), method to call the provided function for each element of the array. The provided function may perform any kind of operation on the element of the given array.


Syntax:

array.forEach(callback(element, index, arr), thisValue)


Example:

<script> 
    // JavaScript to illustrate forEach() method 
    function func() { 
      
        // Original array 
        const items = [12, 24, 36]; 
        const copy = []; 
  
        items.forEach(function (item) { 
            copy.push(item-2); 
        }); 
  
        document.write(copy); 
    } 
    func(); 
</script>


Output:

10,22,34


I hope it can help you...