Javascript for in and for of

Day 4: for in and for of loops

In short, Iterates over statements which are true.


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]; = '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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.