1let arr=[{id:1,title:'A', status:true}, {id:3,title:'B',status:true}, {id:2, title:'xys', status:true}];
2//find where title=B
3let x = arr.filter((a)=>{if(a.title=='B'){return a}});
4console.log(x)//[{id:3,title:'B',status:true}]
1const myArray = [{ userid: "100", projectid: "10", rowid: "0" }, { userid: "101", projectid: "11", rowid: "1"}, { userid: "102", projectid: "12", rowid: "2" }, { userid: "103", projectid: "13", rowid: "3" }, { userid: "101", projectid: "10", rowid: "4" }];
2const myFilter = [{ userid: "101", projectid: "11" }, { userid: "102", projectid: "12" }, { userid: "103", projectid: "11"}];
3
4const myArrayFiltered = myArray.filter((el) => {
5 return myFilter.some((f) => {
6 return f.userid === el.userid && f.projectid === el.projectid;
7 });
8});
9
10console.log(myArrayFiltered);
1let people = [
2 { name: "Steve", age: 27, country: "America" },
3 { name: "Jacob", age: 24, country: "America" }
4];
5
6let filteredPeople = people.filter(function (currentElement) {
7 // the current value is an object, so you can check on its properties
8 return currentElement.country === "America" && currentElement.age < 25;
9});
10
11console.log(filteredPeople);
12// [{ name: "Jacob", age: 24, country: "America" }]
13
1var arr = [1,2,3,4],
2 brr = [2,4],
3 res = arr.filter(f => !brr.includes(f));
4console.log(res);
1function isGreater(element, index, array) {
2 return (element >= 10);
3}
4
5let testElemets = [12, 5, 8, 130, 44].filter(isGreater);
6console.log("Test Value : " + testElemets );