for..in in JS ​
Related Arrays in Javascript
js
let arr = ['Hello', 'Kitty']
for (let i in arr){
console.log(i)
}In any other sane language, this should return
Hello
KittyBut in JS, it returns
0
1Since this looks a bit sane, JavaScript goes the extra mile of making this even more weird by intelligently making the indices string.
js
let arr = ['Hello', 'Kitty']
for (let i in arr){
console.log(typeof(i))
}string
stringOverall, very weird.