I have this javascript code working in firefox, chrome, and safari
for (idx in all_auction_ids){
alert(all_auction_ids[idx]);
};
for the above, instead of getting the values in all_auction_ids
, the first value I get is text of type function that looks like a for loop!
But if I run the code below, it works fine.
for (idx=0;idx<all_auction_ids.length;idx=idx+1){
alert(all_auction_ids[idx]);
};
edit: updates
I did some debugging and found out that, adding Orbited and stomp.js is probably doing something with the array!
for now i am using Tracker1's suggestion jquery's $.each.
more info: http://groups.google.com/group/orbited-users/browse_thread/thread/7fd658cfb166e9fa
array with the problem http://bayimg.com/fAnhaAaBb
array without the problem http://bayimg.com/FaNhEAabb
JavaScript's for/in construct is traditionally for iterating over object member names, not array indices. The more forward-thinking browsers have added features like hidden properties to help cases like Array enumerate in the way you would expect, but IE stilll does it the old-school way and gives you Object members like the 'toString' method when you use for/in over an Array.
The indexed-for is still the canonical JavaScript array loop. (Although you probably mean 'for (var idx=...', and 'idx++' is more common.)
It's worth noting that some libraries such as prototype.js extend Array, so that they have additional properties beyond the internal indexes. This breaks for x in y notation beyond, as other mentioned, that IE will iterate properties. for i=0...i++ is preferred.
Also worth noting is jQuery, prototype and others offer a .each(fn) notation that I actually prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With