When you look at it from the perspective of someone who wants to implement the behavior of a Javascript pseudo-array, you are right that a hash table is the best way to do this, especially. since Javascript arrays do not have a fixed length and should be able to place entries at any index. Arrays in Javascript just look like arrays, but behave more like hashtables.
But in a language that is a little closer to the machine, the performance advantages and the space of using a real array for data that can be effectively stored in the array are quite remarkable, especially since the advantages of using hash tables for this are quite limited by sparse arrays, which is not what you should use an array for. This is really best done with hashtables with integer keys.
Inserting, searching, and deleting is also O (1) for arrays in all cases, but has a much smaller O constant than hash tables (this is not only due to the locality of the cache). And arrays require less space for each record. If you want to delete and insert records so that the following records change their index accordingly, this would be O (n), where n would be the number of records to be moved, but it would also be O (n) for hashtables for this and again with much higher fixed overheads. This is the operation for which you are better off using a linked list. In addition, array growth is less expensive than hash table growth, which may need to rephrase all entries.
All different types of collections have their own particular advantages and disadvantages. That is why there are so many.
source share