๐Ÿ”ฐiterating elements

JS โŸฉ object โŸฉ built-in โŸฉ Array โŸฉ iterating arrays

// โญ๏ธ for-of: treats "holes" as undefined
for (const value of array) {}
for (const [index, value] of array.entries()) {}    // with index

// โญ๏ธ forEach: ignores "holes"
arr.forEach(value => ...)        // .forEach() method

Unlike the for-of loop, forEach() is aware of sparse arrays and does not invoke the function for nonexistent elements.

Last updated