如何使用Ramda通过键值在Array中查找匹配的对象 [英] How to use Ramda to find matching object in Array by key value

查看:153
本文介绍了如何使用Ramda通过键值在Array中查找匹配的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,这给了我 undefined ,但是 R.propEq 应该会在我认为的port中通过键ticker找到匹配的对象?

Currently this is giving me undefined, however R.propEq should find the matching object by key ticker in port I thought?

推荐答案

正如您所说,可以通过将密钥传递给 propEq :

As you say, you can solve it by passing in the key to propEq:

R.find(R.propEq('ticker', 'aa'), port)

另一种选择是使用 eqProps 函数,该函数测试两个对象是否匹配命名密钥:

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.

这篇关于如何使用Ramda通过键值在Array中查找匹配的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆