🔰iterating elements

JSobjectbuilt-inArray ⟩ 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