Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:38:33+00:00 2026-06-12T22:38:33+00:00

Since I am into the basics of JavaScript I am able to create array,

  • 0

Since I am into the basics of JavaScript I am able to create array, but I want to know what we might include in the parenthesis of array like test=new Array(“parameter?”); so I meant what to include as parameter of that javascript array

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:38:34+00:00Added an answer on June 12, 2026 at 10:38 pm

    First, if you find yourself writing new Array, there’s probably a better way to do it. But first I’ll explain the Array constructor and then talk about better ways.

    The Array constructor has two forms: A form that takes zero or one arguments (if that one argument is a number), and a form that takes more than one argument (or just one argument if the argument is not a number). Never use the second form, and avoid using the first one.

    The first form:

    var a = new Array(5);
    

    …creates an array with a length of 5 which has no entries (JavaScript arrays are “sparse,” because they’re not really arrays at all — more on that below). If you don’t supply any argument at all, the length is 0.

    The second form:

    var a = new Array(5, 6);
    

    …creates an array with as many entries as there are arguments (so, two in this case) and uses the arguments to set the values of those entries.

    Note that both the number and type of arguments is important:

    var a = new Array(5);   // Creates an array with length = 5 with no entries
    var b = new Array("5"); // Creates an array with length = 1 and entry [0] = "5"
    

    It’s almost always much better to use array literals.

    The first form above, done with an array literal instead:

    var a = [];
    a.length = 5;
    

    The second form above, done with an array literal instead:

    var a = [5, 6];
    

    Using array literals is “better” (in my view) for several reasons, some of which are more subjective than others:

    1. It’s clearer, and doesn’t have the ambiguity that the Array constructor has. For instance, what does this do?

      var a = new Array(foo);
      

      Answer: It depends (on what foo has it in it, a number or something else). This is just Not Goodtm.

    2. It’s not susceptible to someone overwriting the Array symbol (which they can do) with something else.

    3. It’s more concise and expressive (this is probably the most subjective of the reasons).

    More reading:

    • The ECMAScript (JavaScript) specification on Arrays
    • A myth of arrays (in my blog), which explains how JavaScript arrays aren’t arrays
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's been a while since I got into QCL but I ran into some
I have a milliseconds-since-local-epoch timestamp that I'd like to convert into a milliseconds-since-UTC-epoch timestamp.
I want to create a simple bookmarklet to pass some information from javascript to
i'm not really into basics algorithm programming, so here's my problem. I want to
Hello I want to create a simple blog where users can post comments, but
Since the GOF book was put together well before .Net came into being, are
Am looking into developing an iPhone native app using Titanium Developer Since this is
It's been a long time since I've done C++ and I'm running into some
I find Oleg's docs on Iteratee somewhat difficult to get into. Especially since some
I stumbled upon https://codereview.stackexchange.com/questions/10610/refactoring-javascript-into-pure-functions-to-make-code-more-readable-and-mainta and I don't understand the answer since the user uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.