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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:07:07+00:00 2026-05-27T05:07:07+00:00

non sparse array are contiguous in nature and from 0 to length-1, all index

  • 0

non sparse array are contiguous in nature and from 0 to length-1, all index should return true for ‘in’ operator. It should be true also for empty element.

obj1 = {x:1,y:2};
obj2 = Object.create(obj1);
obj2.z = 5;
var arr = [obj1,obj2,1,,2];

console.log(arr.length); //5
console.log(3 in arr);//false

index 3 is valid.
Why is it returning false?

Note: I am using latest firefox.

It should return false only for sparse array which doesn’t have a specified index number 3.

Update: index 3 is valid so it should return true. in operator doesn’t validate value of at the indexed position, it just validate the validity of index not the 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-27T05:07:08+00:00Added an answer on May 27, 2026 at 5:07 am

    3 in arr is false because arr[3] is never set (and thus the array is indeed sparse).

    Note the double comma in

    var arr = [obj1,obj2,1,,2];
    

    – if you make that

    var arr = [obj1,obj2,1,2];
    

    then 3 in arr becomes true.

    See page 63 in the specification:

    Array elements may be elided at the beginning, middle or end of the element list. Whenever a comma in the
    element list is not preceded by an AssignmentExpression (i.e., a comma at the beginning or after another
    comma), the missing array element contributes to the length of the Array and increases the index of
    subsequent elements. Elided array elements are not defined. If an element is elided at the end of an array,
    that element does not contribute to the length of the Array.

    – in other words, the behavior of your code is identical to

    var arr = [obj1, obj2, 1];
    arr[4] = 2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sparse array in Jscript, with non-null elements occuring at both negative
I have a 3d array containing the non-cubic bounding box of a sparse geometry.
Custom non-fatal exception derive from which class in asp.net 3.5?
Should be available to non-U.S. companies, easy to setup, reliable, cheap, customizable, etc. What
I'm calling a non-.NET dll from my project using P/Invoke, meaning that the .dll
Suppose I have a 2d sparse array. In my real usecase both the number
I need to solve a large, sparse system of linear equations from a program
I have created a sparse matrix using MEX and also created a sparse matrix
The setting is here. X: 6000x8000 non-sparse matrix B: 8000x1 sparse vector with only
MVC3 non-sequential index hidden inputs for model binding.. <input type=hidden name=Index value=whatever /> Does

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.