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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:31:51+00:00 2026-06-14T12:31:51+00:00

I have an array of objects. The constructor is Planet : function(planet) { this.name

  • 0

I have an array of objects. The constructor is

Planet : function(planet)
{
    this.name = planet.name;
    this.percComp = planet.percComp;
    this.preReq = planet.preReq;
}

Is there a way using jquery or underscore to get an object or objects, out of the array based on the objects parameter.

Something like

_getItem(planetArray, Planet.name === 'Mars')
  • 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-14T12:31:52+00:00Added an answer on June 14, 2026 at 12:31 pm

    try Underscore’s where method

    _.where(listOfPlanets, {name: "Mars"});
    

    Say you have the following list of planets – prop is a made up property

    var listOfPlanets = [
        { name: 'Mercury', prop:1},
        { name: 'Venus', prop:2},
        { name: 'Earth', prop:3},
        { name: 'Mars', prop:4},
        { name: 'Jupiter', prop:5},
        { name: 'Saturn', prop:6},
        { name: 'Uranus', prop:7},
        { name: 'Neptune', prop:8} ];
    

    To get the Mars object just do the following. Keep in mind that _.where returns an array of matches. Accessing the index 0 or using _.first will be needed

    var mars = _.where(listOfPlanets, {name: "Mars"})[0];
    console.log(mars.prop);    // 4
    

    Underscore also has a _.find method, which can be used to retrieve only the first match

    var mars = _.find(listOfPlanets, function(p){ return p.name === 'Mars' });
    console.log(mars.prop);    // 4
    

    JSFiddle here: http://jsfiddle.net/jaimem/6bxnK/1/

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

Sidebar

Related Questions

I have an array of 3 objects of keyValue constructor in javacsript: function keyValue(key,
When I have array of objects, when I type the name of variable in
I have simple AJAX function that uses jQuery to return an array of 300
I have created a number objects using an array statement, and I can println
suggest we have an array of class A's objects, and class A's constructor require
I have a JavaScript array of objects like this: box[0] = {...} box[1] =
Is there a way to find out whether a Java function (or a constructor)
I have an array of objects in MATLAB and I've called their constructors in
I have an array of Objects, each containing a Location and a Links array
I have an array of objects and I want to add another object just

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.