I am looking at a sample from mozilla documents about JS and here is this snippet that shows that For..of prints 3, 5, 7, but why not "hello"?
let arr = [3, 5, 7]; arr.foo = "hello"; for (let i in arr) { console.log(i); // logs "0", "1", "2", "foo" } for (let i of arr) { console.log(i); // logs "3", "5", "7" ????? }
for...initerates over property names,for...ofiterates over property values:.hellois the value of the keyfoo.arr[3]is undefined.arr.foois just an arbitrary property of the array, likearr.lengthis, it's not an array element. Only integer-indexed properties are.