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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:48:17+00:00 2026-05-26T14:48:17+00:00

var myArray = new Array(); myArray[‘112’] = 0; myArray.length Why is length 113 in

  • 0
var myArray = new Array(); 
myArray['112'] = 0;
myArray.length

Why is length 113 in above sample? Shouldn’t '112' add a object property for the array and create something similar to myArray = {"112":0}?

Besides this, why is the length 113 and not 1? Since myArray actually only contains 1 value

  • 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-26T14:48:18+00:00Added an answer on May 26, 2026 at 2:48 pm

    Consider this simple example:

    var aa = [];
    aa[3] = 'three';
    alert( aa.length // 4
      + '\n' + aa[2]    // undefined 
      + '\n' + aa.hasOwnProperty('2') // false
    );
    

    The number 3 is used to assign the property name, but it is converted to a string and used as a standard property name (i.e. the string “3”).

    Adding a property named “3” has created one property and set the length to 4 since the length is always set to one more than the largest non-negative integer property name.

    No other property is created, the array is “sparse”, i.e. it doesn’t have sequentially named (numbered) members. A for..in loop can also be used to see that there is only one property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
Is there a way to get indexOf on this array? var myArray = new
What am I doing wrong? Code: sample_txt.text = sat; var myArray:Array = new Array
If I have: var myArray = new Array(); myArray['hello'] = value; How can I
I have a Array of Month Values inside JavaScript . var myarray = new
Here is my array: var myarray = [[d1, sections/Dashboard-summary.html, Dashboard], [add, null, ], [20,
What's the real difference between declaring an array like this: var myArray = new
I have the following array setup, i,e: var myArray = new Array(); Using this
Say I have an array like the following: var myArray = new Array(); myArray[0]
The following two different code snippets seem equivalent to me: var myArray = Array();

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.