Loops and iteration @ MDN web docs
var i = 0;
while (i < 100) {
console.log(i)
i++
}
for (var i=0; i<100; i++) {
console.log(i)
}
const numbers = [1, 2, 1, 2, 3, 4];
let rhythm = "and counting ";
function addRhythmCounter(number) {
console.log(number);
rhythm += number + ", and ";
}
numbers.forEach(addRhythmCounter);
console.log(rhythm);
Array.prototype.forEach() @ MDN web docs
And only object properties! Do not use this on arrays!
let someOne = {
firstname: "Jane",
lastname: "Doe",
age: 42,
}
for (const property in someOne) {
console.log(property, someOne[property])
}
let iterable = ["A", "random", "assortment", "of", 6, "things"];
for (const item of iterable) {
console.log(item)
}
iterable = "A random assortment of many more things";
for (const item of iterable) {
console.log(item)
}