Turp
Turp

Reputation: 708

lodash find in array

I have two arrays.

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"] }
];

I want to use lodash in order to find all the people who have a license in the loan of a state.

i have tried:

_find(loans, "IN");

but that doesn't work for me.

Anyone have an idea?

Upvotes: 2

Views: 12715

Answers (1)

Francesco Pezzella
Francesco Pezzella

Reputation: 1795

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

Upvotes: 7

Related Questions