Reputation: 51
I have recently started working on angular and I need to filter data from an JSON array. Basically I want to display names whose id is less than 100. Below is not working for me.
list : any;
getOptionList(){
this.callingService.getData().pipe(
filter((l) => l.id < 100)
).subscribe(
(l) => { this.list = l;}
)
}
}
Json Array from calling Service
[
{
"id":1,
"name": "A"
},
{
"id":2,
"name": "B"
},
...
]
Upvotes: 0
Views: 5133
Reputation: 1429
this.callingService.getData().subscribe((res: any) => {
let filteredArr = res.filter(data => data.id < 100);
//Here you got the filtered array.
});
It will work for you.
Upvotes: 2