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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:32:52+00:00 2026-05-27T03:32:52+00:00

I have JSON objects that have several properties such as an id and name.

  • 0

I have JSON objects that have several properties such as an id and name. I store them in a JavaScript array and then based on a dropdownlist I want to retrieve the object from the JavaScript array based on its id.

Suppose an object has id and name, how do I select them from my array variable?

var ObjectsList = data;
var id = $("#DropDownList > option:selected").attr("value");
ObjectsList["id=" + id];
  • 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-27T03:32:53+00:00Added an answer on May 27, 2026 at 3:32 am

    Since you already have jQuery, you could use $.grep:

    Finds the elements of an array which satisfy a filter function. The original array is not affected.

    So something like this:

    var matches = $.grep(ObjectsList, function(e) { return e.id == id });
    

    that will leave you with an array of matching entries from ObjectsList in the array matches. The above assumes that ObjectsList has a structure like this:

    [
        { id: ... },
        { id: ... },
        ...
    ]
    

    If you know that there is only one match or if you only want the first then you could do it this way:

    for(var i = 0, m = null; i < ObjectsList.length; ++i) {
        if(ObjectsList[i].id != wanted_id)
            continue;
        m = a[i];
        break;
    }
    // m is now either null or the one you want
    

    There are a lot of variations on the for loop approach and a lot of people will wag a finger at me because they think continue is a bad word; if you don’t like continue then you could do it this way:

    for(var i = 0, m = null; i < ObjectsList.length; ++i) {
        if(ObjectsList[i].id == wanted_id) {
            m = ObjectsList[i];
            break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several string each containing a JSON representation of an array of objects.
Hi I have a JSON object that is a 2-dimentional array and I need
I have an array of json objects like so: [{a:b},{c:d},{e:f}] What is the best
I have several TextField columns on my UserProfile object which contain JSON objects. I've
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have some constants in JavaScript that I'd like to reuse in several files
I have a json object that is actually an arraylist of objects previously converted
I have constructed several web services that successfully serialize my .NET types into JSON.
I have a MongoDB Collection called Questions which holds JSON Objects that look like
I have a json object collection of geo locations that I build in the

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.