The forEach()
method executes a provided function once for each array element
const someArray = [1,2,3,4,5,6,6];
someArray.forEach((value) => {
console.log(value);
});
with elment index:
const someArray = [1,2,3,4,5,6,6];
someArray.forEach((value,index) => {
console.log(value,index);
});
for loop operates on the values sourced from an iterable one by one in sequential order.
const someArray = [1,2,3,4,5,6,6];
for (let index = 0; index < someArray.length; ++index) {
const element = someArray[index];
console.log(element,index);
}