473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

declaring an array with "new Array()" vs "[]"

what exactly is the difference ?

I think that [] is more suitable for declarative arrays, but not
exactly sure why.

TIA

Jul 23 '05 #1
6 2091


sonic wrote:
what exactly is the difference ?


The difference between
new Array()
and
[]
?
Both expressions create (not declare!) an empty array. [] is shorter and
was added to the language later but nowadays browsers that don't support
the [] syntax are extinct so it is pretty much your choice of preference
what you use.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
thanks,

so are you saying is that there is absolutely no difference in
javascript object model between both approaches ?

Jul 23 '05 #3


Correct. Other than semantically, is the same constructor.

Danny

On Mon, 11 Jul 2005 10:46:04 -0700, sonic <so*******@gmail.com> wrote:
thanks,

so are you saying is that there is absolutely no difference in
javascript object model between both approaches ?


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #4
sonic wrote:
so are you saying is that there is absolutely no difference in
javascript object model between both approaches ?


There is a difference:

new Array(30)

is not the same is

[30]

The array literal notation is better.

http://www.JSON.org
Jul 23 '05 #5
Do you mind elaborating as to why it is better ?

Jul 23 '05 #6
VK
> Do you mind elaborating as to why it is better ?

Both Array() and [] are equal if you create (oops... "instantiate") an
empty array. You can check the set of build-in properties/methods. they
are equal (because the same constructor is used).

They treat differently arguments (if you instantiate some array
elements right away).
Array(args) scheme is rather tricky, so [args] leaves you lesser place
for a typo.

Read more here:
<http://www.geocities.com/schools_ring/ArrayAndHash.html#Array_create>

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Auleciems | last post by:
Hi: I'm having trouble using an Object which is created based on the following: Public CarDetail () as Car Where the CLASS "Car" is defined as: Public Class Car
4
by: seesaw | last post by:
class A { public: static A* newA() { return new A; } .... }; In the code, two things not very clear and natural to me: 1. the method newA() is defined as static. 2. newA as a member method...
9
by: James | last post by:
Hi, I am new to C++. I want to directly create a dynamic two-dimension double array, i.e. double pp. I found the "new" is only for one-dimension array, i.e. double *p = new p. How to "new" a...
24
by: Rv5 | last post by:
Rookie c++ question, but Ive spent the last 5 years doing Java, where everytime I created an object I used new. In c++ I can create my objects without and its confusing me just a little. I have...
15
by: b83503104 | last post by:
Hi, class MyClass{ int array_size; HisClass **hisObject; }; I want hisObject to point to an array of HisClass objects. The size of the array is given by array_size.
9
by: Frederick Gotham | last post by:
What are your thoughts on the following code? typedef int Coords; int main() { Coords *const p = new Coords; delete p; }
43
by: Bill H | last post by:
25 years ago every computer came with some form of Basic interpreter so you could use yoru computer without having to buy more software. Is Javascript (teamed with HTML) set to become the new...
1
by: parvtb | last post by:
I know STL vector works. But in case STL is not available, what can one do to allocate large memory size in c++ through operator "new"? For instance, I am writing a sort algorithm, and here's...
30
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.