Hacker News new | ask | show | jobs
by tolmasky 6166 days ago
It is reasonable to expect to be able to set arbitrary properties on an Array and have them behave differently than it's indexes, despite the fact that this is not how it works. The language even suggests this is possible by providing certain properties that are not enumerated (such as "length"). What's worse is that the true answer to why this behaves the way it does is that in JS arrays are (kind of) hashes.
1 comments

Yes and no (as you said). Just expanding: Arrays are an instance of Object with a few specialized methods. Therefore, you can (but should not) assign keys with values to the array and it will apply correctly. However, then you lose a great deal of the advantage of it being an Array.