Javascript weirdness with Node.js

3 Sep 2012

Yesterday, I have found a very weird bug, which causes an irregular behaviour.

I won't explain it here, but here is the problem:

Let's say I have an array: `array = ["a","b","c"];`

Then, I would like to iterate over it… so I've decided to use `for (var i in array)`.

Did you know that:

for (var i in array) { console.log(i + " " + (typeof i)); }

prints

0 string 1 string

Now you can imagine: if you are using `i` and calculate something with it, something WTF-weird will happen.

Yeah… Javascript and Node.js are cool…

Give it a kudos