3 ms·
And in JS, it's an object. Figuring out how to store arbitrary key-value pairs should be one of the first steps in learning a new language, given that every la
by kevinmchugh 13y ago
And in JS, it's an object.
Figuring out how to store arbitrary key-value pairs should be one of the first steps in learning a new language, given that every language has a different name for it.
Associative Array is probably my least favorite name for it, since it implies arrays aren't associative. It was a clojure book that first made me realize an array is a map that only allows ints for keys.
- Skinney 13y agoActually an object in JS stores string keys only, if you try to insert something else it's auto-converted to strings. Array is an object wich stores integer keys. You don't really have a datastructure that stores arbitrary keys in JS (when not including third party libraries). This will be changed with Ecmascript Harmony though (dedicated Map type)
- kilon 13y agoIts also an object in Python , Pharo and most likely Ruby too.
- masklinn 13y agoHe meant that — before ES6 anyway — javascript's "associative array" are objects. As in, they're the basic objects of the languages, generally instances of Object: > {}.__proto__ === Object.prototype true although nowadays you can use `Object.create(null)` to get a bare object, with no prototype: > Object.create(null).__proto__ null
- banachtarski 13y agoWell, there is the distinction between a sparse array and a contiguous one, both of which are technically associative. I associate the former with the term "associative array" though.
- jaredsohn 13y ago> an array is a map that only allows ints for keys Actually, it only allows nonnegative ints for keys. Also, it has the added undesirable property of requiring memory proportional to the largest key value, rather than number of keys.
- justincormack 13y agoNot if it is Fortran.