lodash在数组中查找

Tur*_*urp 2 arrays lodash

我有两个数组.

var loans = [
  { 'id': '1234', 'active': true, 'state': 'CA' },
  { 'id': '5678', 'active': false, 'state': 'IN' }
];

var people = [
    { 'id':'1', 'licenses': ["IN", "FL"] },
    { 'id':'2', 'licenses': ["CA"] }
];
Run Code Online (Sandbox Code Playgroud)

我想使用lodash来查找所有people拥有州政府贷款许可证的人.

我试过了:

_find(loans, "IN");
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用.

有人有想法吗?

Fra*_*lla 7

_.find(people, function(o) {
    return ~o.licenses.indexOf('IN');
});
// { 'id':'1', 'licenses': ["IN", "FL"] }
Run Code Online (Sandbox Code Playgroud)

  • 如果其他人和我一样困惑〜,你的答案可以在这里找到:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators?redloclale = en-美国和redirectslug = Core_JavaScript_1.5_Reference%2FOperators%2FBitwise_Operators (2认同)