I
Ian Osgood
I just wanted to let folks know of one more reason not to use for/in
loops on Arrays.
In the following code:
var u = [1,1]
for (var i in u)
print([i, i+2, i-0+2].join());
print(typeof(i) + ' ' + typeof(i-0));
0,02,2
1,12,3
string number
(i+1) does not obtain the expected results because i is a string!
Always use C-like loops when iterating arrays. JavaScript is not
Python!
Ian
loops on Arrays.
In the following code:
var u = [1,1]
for (var i in u)
print([i, i+2, i-0+2].join());
print(typeof(i) + ' ' + typeof(i-0));
0,02,2
1,12,3
string number
(i+1) does not obtain the expected results because i is a string!
Always use C-like loops when iterating arrays. JavaScript is not
Python!
Ian