Day 4: for in and for of loops
In short, Iterates over statements which are true.
- From Course: Javascript for WP
- MDN for in
- MDN for of
The differences between for of and for in are illustrated below. However, I still can’t wrap my head around it.
Object.prototype.objCustom = function() {};
Array.prototype.arrCustom = function() {};
let iterable = [3, 5, 7];
iterable.foo = 'hello';
for (let i in iterable) {
console.log(i); // logs 0, 1, 2, "foo", "arrCustom", "objCustom"
}
for (let i of iterable) {
console.log(i); // logs 3, 5, 7
}
Leave a Reply