0

A simple internet search of "no associative arrays in javascript" will turn up many results of people saying this, some of them SO answers. They'll say things like "JavaScript doesn't have associative arrays, it has objects." Reading the Wikipedia article on associative arrays, it would appear to me that JS objects are associative arrays. Is this just an old school of thought that the majority doesn't believe anymore? Is it a common misconception? Or are they correct?

Edit: I think the comments here better answer this question than the answers of the questions this has been marked a duplicate of.

Mason
  • 738
  • 7
  • 18
  • 1
    Objects are indeed *like* associative arrays, but they weren't explicitly designed as such. For example, you can't find the length of an object, while languages that do have associative array types supply such array-like facilities. – Pointy Nov 19 '19 at 17:07
  • 4
    It (roughly) depends on which definition of "associate array" you're using. The "technical" definition states only the basic mechanisms (e.g., "length" isn't one of them) but when people think "array" they think of the generally-sequential version, not a generic collection. – Dave Newton Nov 19 '19 at 17:08
  • 1
    Although the Wikipedia article equates maps/dictionaries and associative arrays, some people draw the distinction between a *map* (indexed by key) and an *associative array*, which isn't just a map but is an *ordered map* like PHP's associative arrays, indexed not only by *key* but also by *numeric index*. JavaScript objects vaguely resemble maps, but don't resemble ordered maps. (Although ES2015 does add order for some operations; the order is best ignored.) So that's probably why. – T.J. Crowder Nov 19 '19 at 17:11

0 Answers0