How to use Ramda to find matching object in Array by key value
16,570
As you say, you can solve it by passing in the key to propEq
:
R.find(R.propEq('ticker', 'aa'), port)
Another option is to use the eqProps
function, which tests if two objects match for the named key:
R.find(R.eqProps('ticker', ticker), port)
You can see the first or second version in the Ramda REPL.
Author by
Leon Gaban
Investor, Powerlifter, Crypto investor and global citizen You can also find me here: @leongaban | github | panga.ventures
Updated on June 17, 2022Comments
-
Leon Gaban almost 2 years
var portfolio = [{ticker: "aa"}, {ticker: "bb"}]; var ticker = {ticker:"aa"}; var exist = R.find(R.propEq('ticker', ticker), portfolio) console.log(exist)
Currently this is giving me undefined, however R.propEq should find the matching object by key
ticker
inport
I thought?