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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:44:16+00:00 2026-05-24T22:44:16+00:00

Possible Duplicate: Length of Javascript Associative Array I want to check the length of

  • 0

Possible Duplicate:
Length of Javascript Associative Array

I want to check the length of a multidimensional array but I get “undefined” as the return. I’m assuming that I am doing something wrong with my code but I can’t see anything odd about it.

alert(patientsData.length); //undefined
alert(patientsData["XXXXX"].length); //undefined
alert(patientsData["XXXXX"]['firstName']); //a name

fruits = ["Banana", "Orange", "Apple", "Mango"];
alert(fruits.length); //4

Thoughts? Could this have something to do with scope? The array is declared and set outside of the function. Could this have something to do with JSON? I created the array from an eval() statement. Why does the dummy array work just fine?

  • 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-24T22:44:16+00:00Added an answer on May 24, 2026 at 10:44 pm

    Those are not arrays. They’re objects, or at least they’re being treated like objects. Even if they are Array instances, in other words, the “length” only tracks the largest numeric-indexed property.

    JavaScript doesn’t really have an “associative array” type.

    You can count the number of properties in an object instance with something like this:

    function numProps(obj) {
      var c = 0;
      for (var key in obj) {
        if (obj.hasOwnProperty(key)) ++c;
      }
      return c;
    }
    

    Things get somewhat messy when you’ve got inheritance chains etc, and you have to work out what you want the semantics of that to be based on your own architecture.

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

Sidebar

Related Questions

Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
Possible Duplicate: Get number of checkboxes that are checked in Javascript obj = document.getElementById('myform').elements.length.checked;
Possible Duplicate: Length of Javascript Associative Array hash_table = {a: 131, b: 222, c:313}
Possible Duplicate: Is there a JavaScript function that can pad a string to get
Possible Duplicate: Dynamic array in Stack? How do compilers treat variable length arrays Someone
TL;DR version: I want to avoid adding duplicate Javascript objects to an array of
Possible Duplicate: maximum length of HTTP GET request? how many characters can be sent
Possible Duplicate: Object comparison in JavaScript Is there any method that takes in 2
Possible Duplicate: Importance of varchar length in MySQL table When using VARCHAR (assuming this
Possible Duplicate: Enum values().length vs private field I want to know how which of

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.