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')
try Underscore’s
wheremethodSay you have the following list of planets –
propis a made up propertyTo get the Mars object just do the following. Keep in mind that
_.wherereturns an array of matches. Accessing the index0or using_.firstwill be neededUnderscore also has a
_.findmethod, which can be used to retrieve only the first matchJSFiddle here: http://jsfiddle.net/jaimem/6bxnK/1/