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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:46:39+00:00 2026-06-15T00:46:39+00:00

In javascript I define an array like this var arr = [1,2,3]; also I

  • 0

In javascript I define an array like this

var arr = [1,2,3];

also I can do

arr[-1] = 4;

Now if I do

arr = undefined;

I also lose the reference to the value at arr[-1].

SO for me logically it seems like arr[-1] is also a part of arr.

But when I do following (without setting arr to undefined)

arr.length;

It returns 3 not 4;

So my point is if the arrays can be used with negative indexes, these negative indexes should also be a part of their length**.
I don’t know may be I am wrong or I may be missing some concept about arrays.

  • 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-15T00:46:40+00:00Added an answer on June 15, 2026 at 12:46 am

    SO for me logically it seems like arr[-1] is also a part of arr.

    Yes it is, but not in the way you think it is.

    You can assign arbitrary properties to an array (just like any other Object in JavaScript), which is what you’re doing when you “index” the array at -1 and assign a value. Since this is not a member of the array and just an arbitrary property, you should not expect length to consider that property.

    In other words, the following code does the same thing:

    ​var arr = [1, 2, 3];
    
    ​arr.cookies = 4;
    
    alert(arr.length) // 3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When key name starts with digit, in javascript we can define array-like object like
I would like to define the following in Javascript: var tileXml = new Array();
I know in javascript if I want define an array,I use: var arr=new array();
If I have a javascript object/assoc. array defined like this: function somefunction(options) { var
I have javascript object defined like this: function SocialMiner() { var verbose=true; var profileArray=new
I've been coding javascript like this: var Foo = { something: function() { },
Assuming points are represented using JavaScript Array as [x,y] , how could I define
I'm looking for something similar to Javascript's arguments array: function parent(){ child.apply(this.arguments); } I'm
I have an array of items as follows in Javascript: var users = Array();
I have a knockoutjs viewmodel defined like this: function TestViewModel() { var self =

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.