for
Loop through arrays, NodeLists, and other array-like objects.
let sandwiches = ['turkey', 'tuna', 'ham', 'pb&j'];
// logs 0, "tuna", 1, "ham", 2, "turkey", 3, "pb&j"
for (let i = 0; i < sandwiches.length; i++) {
console.log(i); // index
console.log(sandwiches[i]); // value
}
⏰ Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.
Find this useful? You can support my work by purchasing an annual membership.