Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for Are Javascript arrays primitives? Strings? Objects?

Current License: CC BY-SA 4.0

26 events
when toggle format what by license comment
Oct 25, 2025 at 23:33 history edited Inigo CC BY-SA 4.0
type
May 5, 2023 at 6:56 history edited mwhs CC BY-SA 4.0
Fixed hyperlinks
Mar 13, 2019 at 2:02 comment added Kaiido Arrays have something fundamentally special that is not listed in this answer: Only native Array return true for Array.isArray. That is more special than any of the points made here (since these could all apply to other objects).
May 12, 2014 at 15:26 history edited Šime Vidas CC BY-SA 3.0
edited body
Feb 19, 2011 at 17:16 vote accept Jared Farrish
Feb 19, 2011 at 4:32 comment added Šime Vidas @Jared Yea, in essence. :) However, rephrase this "invoking an object non-primitive type" to this "creating an instance of the type Object".
Feb 19, 2011 at 4:27 comment added Jared Farrish @Šime Vidas - So by using the [] notation, you're invoking an object non-primitive type with special methods meant for indexed arrays? Such as slice, length, etc...? In essense, {} (plus array_methods)
Feb 19, 2011 at 4:23 comment added Šime Vidas @Jared All objects in JavaScript have a set of base features (they are called internal properties in the specification). If you do this: var x = {};, you will create a basic object that has these basic features. However if you do this: var y = [];, you will create an array which is a special kind of object that has all the basic features, but also a bunch of additional special features.
Feb 19, 2011 at 4:16 comment added Jared Farrish @Šime Vidas - Oh now, that's fascinating stuff. Is a regular object different from any other object (such as an Array)? Can you see why I ask these questions? I just want to understand. Help me.
Feb 19, 2011 at 4:07 comment added Jared Farrish @Šime Vidas - "JavaScript does not convert arrays into objects. Arrays can contain non-indexed properties just like objects." And then... "In the realm of JavaScript, there exist only objects and primitive values" How do these two statements jibe? Is this possible?
Feb 19, 2011 at 4:03 comment added Šime Vidas @Jared 1. JavaScript does not convert arrays into objects. Arrays can contain non-indexed properties just like objects. In fact, arrays can do everything that regular objects can do (and a few things more). 2. In the realm of JavaScript, there exist only objects and primitive values. Only those two things. And objects have the characteristics of associative arrays. 3. BTW, I found a good definition of an object in JavaScript: An object is a collection of properties.
Feb 19, 2011 at 3:59 comment added Jared Farrish @Šime Vidas - No, I think it has a lot of relevance, especially if JS is naturally converting an "array" into an "object" if it becomes too "complex" to contain indexes only. In the realm of JS, do associative arrays always == objects?
Feb 19, 2011 at 3:51 comment added Šime Vidas @Jared Associative arrays is a concept that goes beyond JavaScript. Read here: en.wikipedia.org/wiki/Associative_array In JavaScript, objects, ergo, values of the type Object have the characteristics of associative arrays.
Feb 19, 2011 at 3:45 comment added Jared Farrish @Šime Vidas - So... Associative arrays are objects (and not arrays)?
Feb 19, 2011 at 3:38 comment added Šime Vidas @Jared As I said above, in JavaScript, objects are associative arrays.
Feb 19, 2011 at 3:35 comment added Jared Farrish @Šime Vidas - I mean "associative" arrays.
Feb 19, 2011 at 3:34 comment added Šime Vidas @Jared What do you mean by non-indexed array? However, all arrays are objects!
Feb 19, 2011 at 3:31 comment added Jared Farrish @Šime Vidas - That's true. But is declaring it an array better than declaring it an object to begin with? I suppose at this point its obvious that non-indexed arrays are not objects. Is that right?
Feb 19, 2011 at 3:25 comment added Šime Vidas @Jared One scenario where arrays are preferred is when you have a list of non-named items. Like so: ['Peter', 'Mike', 'John']. Here you have an array with three items (which are strings). With regular objects, you would have to name each item individually, like so: {name1: 'Peter', name2: 'Mike', name3: 'John'}.
Feb 19, 2011 at 3:15 comment added Jared Farrish @Šime Vidas - But I just come back to the question, why? If they're the same, with middling differences, what makes one "superior" to others in different situations? Could we forget about JS arrays and just embrace objects? Should we?
Feb 19, 2011 at 3:11 comment added Šime Vidas @Jared Use arrays when the member names would be sequential integers. Use objects when the member names are arbitrary strings or names.
Feb 19, 2011 at 3:06 comment added Jared Farrish @Šime Vidas - So why have an array object? I'm just wondering, is it to expose the .length property? They seem to be so similar.
Feb 19, 2011 at 3:04 comment added Šime Vidas @Jared In JavaScript, all objects are associative arrays.
Feb 19, 2011 at 2:59 comment added Jared Farrish "arrays are just like regular objects" - That's interesting. Arrays, other than a few methods decorating them, are objects, and objects are...? Especially if an associative array is really just "cast" into an object magically. Are associative arrays still arrays in this sense? (I apologize in advance if my use of cast is incorrect.)
Feb 19, 2011 at 2:46 history edited Šime Vidas CC BY-SA 2.5
added 213 characters in body
Feb 19, 2011 at 2:38 history answered Šime Vidas CC BY-SA 2.5
toggle format

AltStyle によって変換されたページ (->オリジナル) /