I am new to JavaScript and lately been coding in PHP which I am looking to port to JavaScript. PHP has a Map
implemented directly into its Array
container class, which does not exists in the default language of JavaScript.
Everyone I seem to read says to use an Object for an associative array, but after reading this, specifically:
Property Lookup
When accessing the properties of an object, JavaScript will traverse the prototype chain upwards until it finds a property with the requested name.
When it reaches the top of the chain - namely Object.prototype - and still hasn't found the specified property, it will return the value undefined instead.
It would seem Object
is not an efficient solution to associative arrays, especially when your desire array may contain 10's of 1000's.
What is an efficient alternative to map/associative array within JavaScript? Is there a good 3rd party library that offers a great container class implemented as map/assoc. array? I need to be able to easily and efficiently create large multi-degree associate arrays for various indexing strategies within my code, thus I need optimal sort and search algorithms.
Forgive me if all this seems obvious, but everything keeps pointing me to implement my assoc. array as an Object and I believe that is not the most optimal approach. Any help and guidance is greatly appreciated.