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

  • Home
  • SEARCH
  • 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 6712199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:13:53+00:00 2026-05-26T08:13:53+00:00

why is the following code showing undefined ? Are we not allowed to create

  • 0

why is the following code showing undefined? Are we not allowed to create an array with a single value? Putting two values won’t show this error. Is this a problem with Javascript?

<script>
var tech = new Array(21);
alert(tech[0]);
</script>
  • 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-05-26T08:13:53+00:00Added an answer on May 26, 2026 at 8:13 am

    new Array(21) creates an array with a length of 21. If you want to create a single-value array, consisting of a number, use square brackets, [21]:

    var tech = [ 21 ];
    alert(tech[0]);
    

    If you want to dynamically fill an array, use the .push method:

    var filler = [];
    for(var i=0; i<5; i++){
        filler.push(i); //Example, pushing 5 integers in an array
    }
    //Filler is now equivalent to: [0, 1, 2, 3, 4]
    

    When the Array constructor receives one parameter p, which is a positive number, an array will be created, consisting of p elements. This feature is can be used to repeat strings, for example:

    var repeat = new Array(10);
    repeat = repeat.join("To repeat"); //Repeat the string 9x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote following code to create a linkbutton programmatically, but its showing like lable
I am not sure why Instruments is showing the following code as leaking 128
Following code is showing undefined in alert messages on clicking the radio buttons. What
I am using the following code to show value return by the function test2
The following code does the trick for showing two divs on the same line
The following code works great in IE, but not in FF or Safari. I
I have the following JQuery code: $(this).text('Options &#x25B4;'); However, the ascii code isn't showing
I'm using map kit and showing user's location using showsUserLocation Im using following code
I have the following code. t is showing as invalid on the second line.
I have MKMapView and I am showing it on viewdidload using following code. However

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.