forEach
Every array includes a forEach method that can be used to loop over the elements in the array.
forEach accepts a callback as a parameter. The callback function is called once for each element in the array. The current element, its index and the full array are provided to the callback as arguments. Often, only the current element or the index are used.
const numbers = [6.0221515, 10, 23];
numbers.forEach((number, index) => console.log(number, index));
// => 6.0221515 0
// => 10 1
// => 23 2
There is no way to stop the iteration once the forEach loop was started. The statements break and continue do not exist in this context.
Backlinks