* Daniel Friesen lists@nadir-seen-fire.com [Thu, 22 Mar 2012 01:40:16 -0700]:
That's the very definition of an array. An array is a list, the keys
are
indexes. By definition you cannot have an index that does not exist.
If PHP arrays are sparse, including numeric ones. They are actually like hashmaps I think so. I don't know whether they use different ways to store numeric and string keys. I haven't studied the low-level implementation. They also have "real" arrays like in C (lower level), however these are the part of SPL: http://php.net/manual/en/class.splfixedarray.php
an item in the array does not exist then the items after it take on
earlier
indexes and the length is shorter. If you have a case where 0 and 2 exists but 1 is not supposed to exist then you're not using an array, you're using a hashtable, map, etc... For that purpose you should be using Object like a hashtable: var h = {} h[0] = 'a'; h[2] = 'c';
You can use for..in on such a thing. And you also shouldn't have to worry about using hasOwnProperty on it. If anyone is stupid enough to set something on Object.prototype a lot more than your script will break.
Ok. Which are the cases when jQuery.each() is preferable? I use it with jQuery selectors. Or, something else as well? Dmitriy