Skip to content

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
Kitty

But in JS, it returns

0 
1

Since 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
string

Overall, very weird.