How to Loop Over an Array in Javascript?
There are several ways to loop over an array in Javascript.
Use for-of:
for (const item of theArray) {
// do something
}
Use forEach:
array.forEach(item => {
// do something
});
Use the old-fashioned for-loop:
for(let idx=0; idx<array.length; i++) {
const item = array[idx];
// do something
// works well with async-await
}