This is a use case of For Of Loop over an Array

PHOTO EMBED

Thu Feb 03 2022 07:33:35 GMT+0000 (Coordinated Universal Time)

Saved by @Abidur_Rahman43 #javascript

let arr = [1, 2, 3, 4, 5];

for (const [i, element] of arr.entries()) {
    if (element % 2 == 0) {
        console.log(`The ${element} is even and the position is ${i}`);
    }
}
content_copyCOPY

This code is for looping in array with index using for loops