Saul Feliz
Sep 14, 2021

--

Thanks for the question @mommollman. It made me review some things.

Check this out:

const arr = [10, 15, 20, 25]for(let i in arr){
console.log(i)
}
// PRINTS OUT: 0, 1, 2, 3
for(let i of arr){
console.log(i)
}
// PRINTS OUT: 10, 15, 20, 25

for..in returns a list of keys on the object being iterated, whereas for..of returns a list of values of the numeric properties of the object being iterated.

--

--

Saul Feliz
Saul Feliz

Responses (1)