jQuery.each weird results
Hey folks,
I'm working on some code at the moment, and i'm using jQuery.each quite
a bit through it. I'm getting some weird results. It seems that when I
do a closure within the each, depending on the input the count value
returns as either a number or a string:
test1 = {'one':1, 'two':2, 'three':3, 'four':4 };
test2 = [1,2,3,4];
// typeof i returns as string
jQuery.each(test1, function(i, item){
console.log(typeof i)
});
// typeof i returns as number
jQuery.each(test2, function(i, item){
console.log(typeof i)
});
This caused me a lot of grief recently, as when I was doing some code
and doing i + 1, I got i1 instead of 2, so I have to do i =
parseInt(i,10) before continuing.
Is this known behavior, or an issue, if so I'll raise a ticket?
Tane