Trying to determine the existence of a value in a collection using Lodash.
If the value exists, return true
; otherwise, return false
.
const d = [{
"country": "India",
"_id": ObjectId("5ad47b639048dd2367e95d48"),
"cities": []
}, {
"country": "Spain",
"_id": ObjectId("5ad47b639048dd2367e95d49"),
"cities": []
}];
Code Snippet:
Countries = ['India', 'Spain']
if (_.has(d, Countries)) {
console.log(true);
} else {
console.log(false);
}
However, it consistently returns False. If there is a more efficient way than utilizing lodash
, I'm open to suggestions.