These collection classes are two simple wrappers around native JavaScript objects
and arrays
. The goal is to leverage the benefits of each, combining the key-based access of the object
type with the ordering of the array
type. Although they are written in TypeScript, the equivalent JavaScript is provided for those who don't wish to use TypeScript in their projects.
The JavaScript object
type allows a property to be indexed by string
or by symbol
. Because these collections wrap the object, providing access through methods, the symbol accessor can't be used (unless directly accessing the underlying object). This means that strings should only be used as keys. Rather than mark the key type as string
, it was left as any
. The reason is that doing so would require all keys to be converted to strings prior to calling the relevant methods. Leaving the key type as any
leverages the normal object behavior, which is to convert the value to a string prior to using it as the property name. This makes it possible to index by number, for example.