In JS, you sometimtes have to keep track of lists. Usernames, sessions, available Pictures ,…
And often, you have to add and delete some of them.
So, how do you handle these lists? There are basically two options:
a) Good old numbered Array
b) Associative Array, key/value store
Both have their advantages and disadvantages.
An array keeps the order, you have numbered keys. However, deleting or finding an element requires you to walk through the array.
So, the question to me was: How about performance? How big is the difference?
Long story short:
In case you do not care about the order and will only have unique keys, use an associative array!
To add a value:
To get a value:
To delete a key/value:
This is easy and performs much better. At least in my quickly hacked, unoptimised test you can find here: Simple test html
If you think I did something wrong, please enlighten me.