The forEach () method is used to call each element of the array and pass the element to the callback function
Main usage scenario: traverse each element of the array
grammar
Traversal array. forEach (function (current array element, current element index number) {//function body})
const arr=['red','green','blue'] arr.forEach(function(item,index){ console.log(item,index) })
be careful:
ForEach mainly traverses arrays
The current array element of the parameter must be written, and the index number is optional