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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:39:42+00:00 2026-05-13T10:39:42+00:00

While looking for the best way to search an array of objects in Javascript

  • 0

While looking for the best way to search an array of objects in Javascript (there doesn’t seem to be a iterate + compare function for that) I came across this post which seems like are really elegant way of doing this.

However I have some questions:

  1. Javascript doesn’t have associative arrays. These seems like one. What gives?
  2. This seems like a very elegant solution but how does it stack up against the competition?
    • “Pass the array and comparison function” – means several specific comparison functions for various searches.
    • “Optimised findByX functions” – means optimised searches for each type needed.
    • “scalalala method” – which I suspect would be the slowest but most elegant.

Also how would you go about taking a reponse from AJAX and creating an array with a similar structure to this? Most tutorials hand-pick and roll the examples to demonstrate the associativity of arrays but not how that could be used practically.

Is there any pitfalls to using this method?

Decent links (beyond this) would be appreciated.

Thanks.

UPDATE:
This is what I am having trouble with. If I have data coming back from the server similar to this:

$.getJSON("map.php?jsoncallback=?", function(data) {
    for (var x=0,xx=data.stars.length; x<xx; x++) {
        stars.push( 
            new Star(
                data.stars[x].id,
                data.stars[x].xpos, data.stars[x].ypos,
                data.stars[x].name, data.stars[x].owner
            )
        );
    }
});

Where Star is a class:

function Star(id, x, y, n, o) {
    this.id = id;
    this.x = x; this.y = y;
    this.name = n;  this.owner = o;
}

So how do I turn this into the “associative” style array?

  • 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-13T10:39:42+00:00Added an answer on May 13, 2026 at 10:39 am

    JavaScript Array objects should be used with numeric sequential indexes, but you can use plain objects, that are simply a collection of key/value pairs.

    In the code you link, the function looks for an object inside an array.

    Note that this code has jQuery as a dependency (it uses $.grep).

    For performance I would recommend you to use the standard Array.prototype.filter method, modern browsers provide a native implementations that is really fast, compared to a custom implementation.

    For compatibility (mostly for IE), you can include the method implementation on the above link.

    This method is really easy to use, and is now part of the ECMAScript 5th Edition Specification (PDF) (Section 15.4.4.20):

    var filtered = existingArray.filter(function (obj) {
      return obj.property == someValue;
    });
    

    The above code will give you back a new filtered array with all the objects that match the condition specified in the filter callback function.

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

Sidebar

Ask A Question

Stats

  • Questions 296k
  • Answers 296k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Of course, it's going to be different for everyone, but… May 13, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer Some processors have two types of pointers, a near pointer… May 13, 2026 at 7:07 pm
  • Editorial Team
    Editorial Team added an answer The encrypted private key is a blob. PGP usually stores… May 13, 2026 at 7:06 pm

Related Questions

I am working on a project for my computer security class and I have
As a follow up question related to my question regarding efficient way of storing
Say I want to output a huge set of search results, as XML, into
I’m looking for some advice. I recently wrapped up a project where I inherited
I am trying to find a trend in several datasets. The trends involve finding

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.