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}]
1ngOnInit() {
2 this.booksByStoreID = this.books.filter(
3 book => book.store_id === this.store.id);
4}
1const array = [
2 {
3 username: "john",
4 team: "red",
5 score: 5,
6 items: ["ball", "book", "pen"]
7 },
8 {
9 username: "becky",
10 team: "blue",
11 score: 10,
12 items: ["tape", "backpack", "pen"]
13 },
14 {
15 username: "susy",
16 team: "red",
17 score: 55,
18 items: ["ball", "eraser", "pen"]
19 },
20 {
21 username: "tyson",
22 team: "green",
23 score: 1,
24 items: ["book", "pen"]
25 },
26
27];
28//FILTER MEMBERS IN TEAM "RED"
29const filterArray=array.filter(word=>word.team==="red")
1var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
2
3const result = words.filter(word => word.length > 6);
4
5console.log(result);
1function objectFilter = (obj, predicate) =>
2 Object.keys(obj)
3 .filter( key => predicate(obj[key]) )
4 .reduce( (res, key) => (res[key] = obj[key], res), {} );
5
6// Example use:
7var scores = {
8 John: 2, Sarah: 3, Janet: 1
9};
10
11var filtered = objectFilter(scores, num => num > 1);
12console.log(filtered);