-1

is this:

var arr = {};

the same as

var arr = new Array();

?

Fran Verona
5,4866 gold badges50 silver badges87 bronze badges
asked Feb 7, 2011 at 13:47

5 Answers 5

7

It is not the same.

var arr = {};

initializes an object. If you want an array:

var arr = [];
answered Feb 7, 2011 at 13:48
Sign up to request clarification or add additional context in comments.

1 Comment

4

not exactly. var arr = []; is more like it.

answered Feb 7, 2011 at 13:48

Comments

2

No.

var arr = {}; // creates a new object with no properties

But

var arr = []; // creates a new blank array
answered Feb 7, 2011 at 13:49

Comments

1

var arr = {}; creates object

answered Feb 7, 2011 at 13:49

Comments

1

No, it's not: You're confusing array literals

var arr = []; // same as new Array()

with object literals

var obj = {}; // same as new Object()
answered Feb 7, 2011 at 14:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.