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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:57:36+00:00 2026-05-13T06:57:36+00:00

I have an array like this: var anArray = [ { name: scala, type:

  • 0

I have an array like this:

var anArray = [
    { name: "scala",  type: "a" },
    { name: "abc",    type: "b" },
    { name: "test",   type: "a" },
    { name: "ruby",   type: "c" },
    { name: "erlang", type: "a" },
];

I want to find items based on the item property. I currently do it using jQuery. something like this;

Array.prototype.find_by_key = function(key, value) {
    return $.grep(this, function(item){
        return (item[key] == value);
    });
}

var whatIHaveFound = anArray.find_by_key("type", "a"); // find items which the item property: "type" equals "a"

is there some better way to do this in javascript? or is there some algorithm to do this better and quickly? when the array has many items. this may be very slow. any ideas? thanks.

  • 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-13T06:57:37+00:00Added an answer on May 13, 2026 at 6:57 am

    Wiser minds may correct me, but I would think you’re going to have to iterate through every time (at more or less similar speeds), unless:

    You know that you’re going to repeat searches and that some keys are more likely to be searched than others. You might bias the collection then so that it’s not flat, but is presorted according to your terms. Thus your collection would become:

    var groupedByType = 
    {"a":[{name:"scala"},{name:"test"}, {name:"erlang"}],  
    {"b":[{name:"abc"}],  
    {"c":[{name:"ruby"}]};  
    

    Alternatively you might try memoizing your collection access, such that after you’ve done a search you record the search terms and results, in this case storing it in the memo cache as

    ["type","a"]:[
    { name: "scala",  type: "a" },  
    { name: "test",   type: "a" },  
    { name: "erlang", type: "a" }]
    

    Pros and cons of this: It’s very fast to access previously executed searches, if the underlying data has not changed in a way that deprecates your cache. On the other hand, it means that you have to control data access (I like to store my data inside a closure in these cases, so that I only have to expose mutators – sort of a lightweight OO but with more protection), and you may find it more performant to discard your cached data when it’s modified than to try to work out deltas, depending on how your data is structured.

    What I would emphasize above everything else though, is to make absolutely sure that you need any optimization at all. Is this subsection fast enough? Can you bring your app up to speed another way? If you’re writing a clientside search engine or something, you’re probably going to want to go a little bit further into it than just working out which of the jQuery iterators is fastest.

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

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • 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 You can use this (msdn) to draw the control to… May 13, 2026 at 7:58 pm
  • Editorial Team
    Editorial Team added an answer #wrapper { height:auto !important; margin:0 auto -74px; min-height:100%; } You… May 13, 2026 at 7:57 pm
  • Editorial Team
    Editorial Team added an answer You can keep coding it manually but using GroovyBuilders (link)… May 13, 2026 at 7:57 pm

Related Questions

I have a Javascript object that basically represents a Row in an .NET GridView.
Sorry, I know this is programming 101, but I can't find any good documentation...
I'm passing a table of up to 1000 rows, consisting of name, ID, latitude
I have an array of strings var controlsToGet = new[] {lblHome,lblContact}; I have List<LanguageControl>
I have an object options : options = {title : 'title1', name : 'name1',

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.