Skip to content

Instantly share code, notes, and snippets.

@waynebaylor
waynebaylor / iterators.md
Created Mar 26, 2021
Javascript Iterators, Iterables, and Generators
View iterators.md

Iterators

An iterator provides a way to iterate over a collection of values. One of the most common uses for an iterator is in for...of loops. A for...of loop will loop over the values given to it, but how does it know what order to use?

For example, why does this for...of loop start at index 0? Why not start at the end and go backwards?

const arrayOfFruits = ['apple', 'orange', 'banana', 'pear'];

for (const val of arrayOfFruits) {