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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:08:07+00:00 2026-06-04T00:08:07+00:00

I have a JavaScript associative array (or some may prefer to call it an

  • 0

I have a JavaScript associative array (or some may prefer to call it an object) like, say

var quesArr = new Array();
quesArr["q101"] = "Your name?";
quesArr["q102"] = "Your age?";
quesArr["q103"] = "Your school?";

Is there a built-in function that could get the length of this array, or a solution in jQuery or another library? Currently quesArr.length would give 0, as most of you must be knowing.

Please don’t suggest iterating over the entire array/object as mentioned in this question, because the array/object which I have is very large.

Is there a way I could proceed with this?

  • 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-04T00:08:08+00:00Added an answer on June 4, 2026 at 12:08 am

    No, there is no built-in property that tells you how many properties the object has (which is what you’re looking for). The closest I can think of for plain objects (keep reading for an alternative) are things that return arrays of property keys (which you can then get length from):

    • Object.keys – Returns an array of the object’s own, enumerable, string-keyed properties.
    • Object.getOwnPropertyNames – Like Object.keys, but includes non-enumerable properties as well.
    • Object.getOwnPropertySymbols – Like Object.getOwnPropertyNames, but for Symbol-keyed properties instead of string-keyed properties.
    • Reflect.ownKeys – Returns an array of an object’s own properties (whether or not they’re enumerable, and whether they’re keyed by strings or Symbols).

    For instance, you could use Reflect.ownKeys like this:

    var quesArr = new Array(); // Keep reading, don't do this
    quesArr["q101"] = "Your name?";
    quesArr["q102"] = "Your age?";
    quesArr["q103"] = "Your school?";
    console.log(Reflect.ownKeys(quesArr).length); // 4 -- includes the built-in
                                                  // `length` property!

    Notice that showed 4, not 3, because of the built-in length property of arrays. Since you don’t seem to be using the Array features of the object, don’t make it an array. You could make it a plain object:

    const questions = {};
    questions["q101"] = "Your name?";
    questions["q102"] = "Your age?";
    questions["q103"] = "Your school?";
    // Or just:
    // const questions = {
    //    q101: "Your name?",
    //    q102: "Your age?",
    //    q103: "Your school?",
    // };
    console.log(Reflect.ownKeys(questions).length); // 3

    But since you want to know how many things are in it, you might consider using a Map, because unlike objects, Map instances do have a property telling you how many entries they have in them: size.

    const questions = new Map();
    questions.set("q101", "Your name?");
    questions.set("q102", "Your age?");
    questions.set("q103", "Your school?");
    // Or you can pre-fill the `Map` by passing an array of `[name, value]` arrays:
    // const questions = new Map([
    //     ["q101", "Your name?"],
    //     ["q102", "Your age?"],
    //     ["q103", "Your school?"],
    // ]);
    console.log(questions.size); // 3
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Javascript associative array (a.k.a. hash, a.k.a. dictionary): var a
I have a JavaScript object that is treated as an associative array. Let's call
I am trying to have a javascript object tree behave like a php associative
Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
I have a collection of objects in JavaScript like this: Object collection = new
I have 'multidimensional associative' javascript array (which in fact is object with properties as
I have javascript string variable with var sttr=We prefer questions that can be answered
I have an array of items as follows in Javascript: var users = Array();
I wanted to make an associative array in Javascript in which I would have
I know that I can create an associative array like this: var MyAssocArray =

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.