user3808307
user3808307

Reputation: 1569

Why is lodash some not working here as I expect?

I have an array

arr = ["jenny", "lucy", "jason"]

I do

_.some(arr, "jenny")

and it throws false

Upvotes: 1

Views: 2267

Answers (2)

Usman Wali
Usman Wali

Reputation: 417

Your call to _.some needs to have a function callback as its second parameter:

arr = ["jenny", "lucy", "jason"];
 _.some(arr, function(val) {return val === 'jenny'});

Upvotes: 2

Ele
Ele

Reputation: 33726

In your case (an array) the predicate must be a function to check the values.

var arr = ["jenny", "lucy", "jason"]
var result = _.some(arr, (x) => x === "jenny");

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>

Resource

Upvotes: 5

Related Questions