lets say that I have this array of objects.
var initialData = [{Title:"Hat",Price:49.95},
{Title:"Pants",Price:78.25},
{Title:"Shirt",Price:12.34}];
I know that I can find which objects have the Title = "Hat" using the _.where function.
// underscore method
console.log( _.where(initialData, {Title:"Hat"}));
But what if I want to look for all the object that contain Title = "Hat" or "Shirt"? Is possible to do it with the same _.where function?
Thanks in advance
Thanks Simon. I did what you suggested, and the code below is working.
var initialData = [{Title:"Hat",Price:49.95},
{Title:"Pants",Price:78.25},
{Title:"Shirt",Price:12.34}];
var match=['Hat', 'Shirt'];
//underscore method
console.log( _.filter(initialData, function(num){ return _.contains(match,num.Title) }));
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With