Associative Arrays in JavaScript
Some developers misuse the Array constructor to create an associative array. However, this is not a good way of doing this as all the methods/properties available to an array (length, index, sort etc) will not work. var foo = []; // [] is the same as 'new Array()' foo["bar"] = "baz"; alert(foo.length); When the alert fires, it will return '0' instead of '1'. As it doesn't function as a proper array, you may as well use an object instead: var foo = {}; // {} is the same as 'new Object()' foo["bar"] = "baz"; However, you can't see how many items there are without looping through the object. I have written a simple class that can be used that offers this (through the function 'getSize()' as well as a few other methods). As a result, you can't have anything with the keys 'getSize', 'remove', 'toString' and 'toArray'. var AssociativeArray = function() { if(argu...