0
For loop difference
Can i get a detail explanation of the difference of "of" and "in" in for loop For(let e of/in [array])
1 Odpowiedź
+ 3
Tomoe
'in' gives you index of each value
'of' gives you each value of the array
If you want to get value using 'in' then you need to access with index
var arr = ['a', 'b', 'c', 'd']
for (var i in arr) {
console.log(i)
}
console.log("-----")
for (var j of arr) {
console.log(j)
}
console.log("------")
for (var k in arr) { //here k is index of each value
console.log(arr[k]) //accessing value using index
}