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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:03:16+00:00 2026-06-10T12:03:16+00:00

I came across to this problem. I have defined an array and populated it

  • 0

I came across to this problem. I have defined an array and populated it with objects,
If first case my data array look like this on firebug console:

data = [
    Object { code="6", id="1073148", key="82628835"},
    Object { code="17", id="2073140", key="83628837"}
]

And when I check its length I get 2 from data.length

In second case I have

data = [
    [Object { code="6", id="1073148", key="82628835"}],
    [Object { code="17", id="2073140", key="83628837"}]
]

And this one returns 2 also when I check data.length

Can someone explain me why I am getting same lengths for this different cases.

Edit after some answers
data is populated using $.parseJSON what is confusing to me is
in fist case I can access value of code by data[0].code and in second case
I cannot access it by data[0][0].code

If they are the same children of array why I cannot access them using same indices.
Then why they have same length?

  • 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-10T12:03:17+00:00Added an answer on June 10, 2026 at 12:03 pm

    Because data.length is only 2 in both cases

    Further explained:

    Each object contains multiple values, however, you’re not calling for the length of those objects.

    data.length = get me the count of children in data (not grandchildren and cousins and neices and nephews) JUST CHILDREN.

    In both of those cases, regaurdless of what the objects are, there is 2 of them in data, thus the length = 2

    To furter:

    It doesn’t matter what those objects are, heck you could have one string and one child array, that would still return 2 because it would be 2 objects inside the object we’re asking for length on

    UPDATE to answer second question brought up

    The reason for access is simple, in the first instance, your children are typical Objects, as seen in your example:

    data = [ 
        //  These two CHILDREN are Typical Objects
        Object { code="6", id="1073148", key="82628835"}, 
        Object { code="17", id="2073140", key="83628837"} 
    ] 
    

    Thus you can access obect 1 as data[0].

    HOWEVER in your second example, the children are ARRAY Type Objects, thus, each child could have multiple values. For Example:

    data = [   
        [Object { code="6", id="1073148", key="82628835"}],   
        [Object { code="17", id="2073140", key="83628837"}]   
    ]  
    //  Your example here has 2 children but each child is an ARRAY type Object,
    //  Each array has one child which is the object in each one
    // thus you can call data[0][0] & data[1][0]
    //  Could also be 
    data = [   
        [Object { code="6", id="1073148", key="82628835"},   
        Object { code="17", id="2073140", key="83628837"}]   
    ]  
    // in this later case, there is only one child
    //  this one child, like in your example, is an ARRAY, but in this later example,
    //  it has TWO children of its own
    // thus you can call data[0][0] and data[0][1]
    

    As you can see, your second example does NOT have two children OBJECTS, instead it contains 2 Children ARRAYS that each contain one child object. Thus the need to get object 1 becomes data[0][0]

    Where data[0] is getting the first array child and the second [0] is getting that arrays child object

    Get it?

    If not just let me know!

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

Sidebar

Related Questions

I came across this problem when trying to decode json into an array ,
I've came across on this problem, I have a sever running apache and php.
I came across this problem at work, and though I have a solution, I
I have been thinking of this problem for some time now,I came across this
I have came across this problem a few times and can't seem to figure
I came across this problem, I have a number of type long which represents
I'm practising on threading and came across this problem. The situation is like this:
I came across this problem,I have got an algorithm that I need to implement
I have came across this problem when using pointer to pointer to a char:
I came across this problem when I want to check what I input is

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.