javascript - Find an object in array of objects using underscore.js -


have following sctructure

var myarr = [ {code: 'uy', name: "testdfdgf"}]; 

i need pull object out of array code='uy'.

what proper way using _underscore.js (i don't want traverse through array)

thank you

from underscorejs.org

findwhere_.findwhere(list, properties) looks through list , returns first value matches of key-value pairs listed in properties.

if no match found, or if list empty, undefined returned.

_.findwhere(publicservicepulitzers, {newsroom: "the new york times"}); => {year: 1918, newsroom: "the new york times", reason: "for public service in publishing in full many official reports,
documents , speeches european statesmen relating progress , conduct of war."}

so essentially:

var codeuy = _.findwhere(myarr, {code: 'uy'}); 

underscore traverse array find this, don't think can around it, should stop @ first match;


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -