[英]Filter Json Array Data in Typescript
I have recently started working on angular and I need to filter data from an JSON array.我最近开始研究 angular,我需要从 JSON 数组中过滤数据。 Basically I want to display names whose id is less than 100. Below is not working for me.
基本上我想显示 id 小于 100 的名称。下面对我不起作用。
list : any;
getOptionList(){
this.callingService.getData().pipe(
filter((l) => l.id < 100)
).subscribe(
(l) => { this.list = l;}
)
}
}
Json Array from calling Service来自调用服务的 Json 数组
[
{
"id":1,
"name": "A"
},
{
"id":2,
"name": "B"
},
...
]
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.它会为你工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.