I am using a JS array for map identifiers for actual elements, i.e. for a keystore. I would like to go through all the elements. I tried several methods, but everyone has their caveats:
for (var item in map) {...}
Iterates over all the properties of an array, so it will also include functions and extensions for Array.prototype. For example, someone in the Prototype library will slow down existing code in the future.
var length = map.lenth;
for (var i = 0; i < length; i++) {
var item = map[i];
...
}
works but just how
$.each(map, function(index, item) {...});
They iterate over the entire range of indexes 0..max (id), which has terrible flaws:
var x = [];
x[1]=1;
x[10]=10;
$.each(x, function(i,v) {console.log(i+": "+v);});
0: undefined
1: 1
2: undefined
3: undefined
4: undefined
5: undefined
6: undefined
7: undefined
8: undefined
9: undefined
10: 10
, . , , undefined . ( , IE)?