Sometimes, we want to use the includes method in lodash to check if an object is in the collection with JavaScript.
In this article, we’ll look at how to use the includes method in lodash to check if an object is in the collection with JavaScript.
How to use the includes method in lodash to check if an object is in the collection with JavaScript?
To use the includes method in lodash to check if an object is in the collection with JavaScript, we can use the some
function.
For instance, we write
const hasB = _.some([{ a: 1 }, { b: 2 }], { b: 2 });
to call some
with the array [{ a: 1 }, { b: 2 }]
that we want to check if { b: 2 }
is in the array.
it should return true
since { b: 2 }
is in the array.
Conclusion
To use the includes method in lodash to check if an object is in the collection with JavaScript, we can use the some
function.