This question is similar to this one Jquery filter array of object with loop but this time I need to do the filter with an array of objects.
Exemple:
I have
You can use jquery map, this return one array of matches:
var _filter=function(arr_data,arr_filter){
return $.map( arr_data, function( n ) {
for(var f in arr_filter){
if(arr_filter[f].userid == n.userid && arr_filter[f].projectid == n.projectid){
return n;
}
}
});
}
var resp = _filter(myArray,myFilter);
console.log(resp);
based on @Renato his answer, but shorter:
const myArray = [{ userid: "100", projectid: "10", rowid: "0" }, ...];
const myFilter = [{ userid: "101", projectid: "11" }, ...];
const myArrayFiltered = myArray.filter(array => myFilter.some(filter => filter.userid === array.userid && filter.projectid === array.projectid));
var filtered = [];
for(var arr in myArray){
for(var filter in myFilter){
if(myArray[arr].userid == myFilter[filter].userid && myArray[arr].projectid == myFilter[filter].projectid){
filtered.push(myArray[arr].userid);
}
}
}
console.log(filtered);