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
in port
I thought?
Ah it was a simple mistake, I forgot to pass in the exact key from the ticker object.
R.propEq('ticker', ticker.ticker)
This is how I now solve my problem in my app:
const exists = R.find(R.propEq('ticker', this.ticker.ticker));
this.inPortfolio = !!exists(portTickers);
console.log('this.inPortfolio', this.inPortfolio)
// True or false
来源:https://stackoverflow.com/questions/41351542/how-to-use-ramda-to-find-matching-object-in-array-by-key-value