Answers for "javascript filter array of objects with multiple conditions"

2

filter using two array of objects

const arr1 = [{id:'1',name:'A'},{id:'2',name:'B'},{id:'3',name:'C'},{id:'4',name:'D'}];
const arr2 = [{id:'1',name:'A',state:'healthy'},{id:'3',name:'C',state:'healthy'}];
const filterByReference = (arr1, arr2) => {
   let res = [];
   res = arr1.filter(el => {
      return !arr2.find(element => {
         return element.id === el.id;
      });
   });
   return res;
}
console.log(filterByReference(arr1, arr2));
Posted by: Guest on May-24-2021
1

javascript filter array multiple conditions

var filter = {
  address: 'England',
  name: 'Mark'
};
var users = [{
    name: 'John',
    email: '[email protected]',
    age: 25,
    address: 'USA'
  },
  {
    name: 'Tom',
    email: '[email protected]',
    age: 35,
    address: 'England'
  },
  {
    name: 'Mark',
    email: '[email protected]',
    age: 28,
    address: 'England'
  }
];


users= users.filter(function(item) {
  for (var key in filter) {
    if (item[key] === undefined || item[key] != filter[key])
      return false;
  }
  return true;
});

console.log(users)
Posted by: Guest on July-01-2021
0

javascript find object in array by multiple property values

let serverProposal = lobby.proposals.find( (p) => p.author == userID && p.isSubmitted == false);
Posted by: Guest on September-29-2020

Code answers related to "javascript filter array of objects with multiple conditions"

Browse Popular Code Answers by Language