let arr=[{id:1,title:'A', status:true}, {id:3,title:'B',status:true}, {id:2, title:'xys', status:true}];
//find where title=B
let x = arr.filter((a)=>{if(a.title=='B'){return a}});
console.log(x)//[{id:3,title:'B',status:true}]
let people = [
{ name: "Steve", age: 27, country: "America" },
{ name: "Jacob", age: 24, country: "America" }
];
let filteredPeople = people.filter(function (currentElement) {
// the current value is an object, so you can check on its properties
return currentElement.country === "America" && currentElement.age < 25;
});
console.log(filteredPeople);
// [{ name: "Jacob", age: 24, country: "America" }]
how to filter list of objects by an array in javascript
var array = ['cat','dog','fish','goat']
var objects = [{pet:'cat', color:'brown'},{pet:'dog', color:'black'},{pet:'gecko', color:'green'}]
//finds the objects that match something in the list with the key pet.
var filteredObjects = objects.filter(function(obj){
return array.indexOf((obj.pet).toString()) > -1;
});
console.log(filteredObjects)
how to filter an array by list of objects in javascript
var array = ['Jane','Donna','Jim','Kate']
var objects = [{name:'Jane', age:25},{name:'Jim', age:30}]
//finds the items in the array that have names within the array of objects.
var filtered = array.filter(r => objects.findIndex(obj => obj.name == r) > -1 )
console.log(filtered)