JS for each Loop

Last Updated: March 16, 2022
const numbers = [1, 2, 3, 4, 5];

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

If you want to get index you can use the following code

numbers.forEach((number, index) => {
    console.log('Index: ' + index + ' Value: ' + number);
});
Test