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 5977293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:20:59+00:00 2026-05-22T21:20:59+00:00

In JavaScript, if you set an array to be of size 5 ( var

  • 0

In JavaScript, if you set an array to be of size 5 ( var foo = new Array(5); ), is this just an initial size? Can you expand the number of elements after it is created. Is it possible to do something like this as well – arr = new Array() and then just assign elements one by one? Thanks in advance 🙂

  • 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-22T21:21:00+00:00Added an answer on May 22, 2026 at 9:21 pm

    Yes it is just an initial size, and it is not required. If you don’t use a single number, you can immediately populate.

    It is also more common to use the simpler [] syntax.

    var arr = ['something', 34, 'hello'];
    

    You can set (or replace) a specific index by using brackets:

    arr[0] = "I'm here replacing whatever your first item was";
    

    You can add to the end by using push:

    arr.push('add me');
    

    There may be faster performance in some browsers if you do it like this instead:

    arr[arr.length] = 'add me';
    

    You can add something at any index.

    You can remove an item completely using splice:

    arr.splice(0, 1); // remove first item in the array (start at index 0, with 1 being removed)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a javascript set of functions that I made. This
I am trying to set a javascript date so that it can be submitted
How can I set a break point in a javascript function and have the
I'd like an input field that I can have javascript set certain attributes for,
Is there a way to set every element of a Javascript typed array (i.e.
This is from Crockford's JavaScript: The Good Parts var is_array = function (value) {
I was wondering how could I reload any website using javascript and set it
I'm trying to set some javascript data (json) in my markup by calling a
How do I generate page numbers for a multi page data set using javascript?
I am trying to set the margin of an object from JavaScript. I am

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.