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

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Are Javascript arrays primitives? Strings? Objects?

Are arrays merely objects in disguise? Why/why not? In what way(s) are they (such/not)?

I have always thought of arrays and objects in JS as essentially the same, primarily because accessing them is identical.

var obj = {'I': 'me'};
var arr = new Array();
arr['you'] = 'them';
console.log(obj.I);
console.log(arr.you);
console.log(obj['I']);
console.log(arr['you']);

Am I mislead/mistaken/wrong? What do I need to know about JS literals, primitives, and strings/objects/arrays/etc...?

Are arrays/objects merely strings in disguise? Why/why not? In what way(s) are they (such/not)?

Answer*

Draft saved
Draft discarded
Cancel
6
  • Now see, this jibes with what I understand. The three types. But how to explain Object, in which everything else is constructed, except arrays? Are we only talking about default method prototypes? "Yes, a JavaScript array is an "object" but it is not an instance of "Object" This gets to the heart of what I am inquiring about. Commented Feb 19, 2011 at 3:04
  • And yes, Crockford is the reason Javascript is taken seriously, IMO. He's been organizing sanity on the Javascript front for too long to remember (at least since 2004, earlier?). Commented Feb 19, 2011 at 3:07
  • @Jared You know Crockford but haven't watched his most fundamental JavaScript video series? Go watch it now! :) Commented Feb 19, 2011 at 3:35
  • @jsummers - So Arrays are fancy character arrays with self-defined special methods? Commented Feb 19, 2011 at 3:38
  • @Šime Vidas - Yeah, I know. Crockford is god. The point here is to extract as much meaning as possible, as opposed to my own stochastic learning processes. I want there to be a meaning that would have been meaningful for me, back then (Thanks Thau!). Commented Feb 19, 2011 at 3:41

lang-js

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