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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:47:23+00:00 2026-05-29T17:47:23+00:00

Background I have an Array of data in a result object returned by an

  • 0

Background

I have an Array of data in a result object returned by an Ajax call. The data looks like this:

{ Name="User1 Name1", FirstName="User1", Id="005400000001234567", more...}
{ Name="User2 Name1", FirstName="User2", Id="005400000001234568", more...}

Where each item looks like this:

{
    Id:"005400000001234567",
    Name:"User Name",
    FirstName:"User",
    LastName:"Name",
    Title:"Manager"
}

Question

I want to be able to retrieve data either by Id (returning a single user) or by Title (returning an array of users). What would be the best way to go about doing that using JavaScript or jQuery?

Example

Here’s what I’ve attempted so far:

function GetAllUsers()
{
    AllUsersById = new Object();

    MyClass.MyAjaxMethod(function(result,event) {
        if(result) { 
            j$(result).each(function(index,item)
            {
                AllUsersById[item.Id] = item;
            });
        }
    });
}

The code I have above is great for indexing by Id, but I’m not sure what to do for Title.

Additional Details

Also, by the way, there are about 1000 records, and I need this to be fairly efficient. (This is one of the reasons I’m getting the data right away, when the document is ready. I’m not an expert on JavaScript or jQuery efficiency, though. Let me know if you have a better way.)

Any ideas? Thanks in advance!

  • 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-29T17:47:24+00:00Added an answer on May 29, 2026 at 5:47 pm

    Seems like you’re looking for .grep(). Using .grep you could create a generic function that would filter:

    function findInJson (json, key, value) {
        return $.grep(json, function (obj) {
            return obj[key] == value;
        });
    }
    
    // With your data getting a specific user by id
    findInJson(yourJSON, "Id", "005400000001234567");
    
    // Getting a set of users by title
    findInJson(yourJSON, "Title", "Manager");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: In Ruby I have a 2d array like the following: count[[english_word, french_word]] =
I have this code in my create.js.erb file: pollingAJAX(); function pollingAJAX() { $.ajax({ method:
I have used this code to load data from a plist. -(void)loadOrCreateData { NSLog(@Start
Have only one question How to right dealloc object when app goes to background
I have a JTable and am passing a data array into the TableModel .
A little background, this began in the question: Custom data type (Structures) vs arrays
I have an Nx4 array of vertices that I'd like to plot using glVertexArray
My Task Background : I have list of data items and have to calculate/aggregate
Quick background, I am using Netbeans to develop this (I don't have much experience
Assume that I have some array of data (a vector to be specific). Can

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.