[英]How to filter an array of objects according to an attribute in Javascript
使用过滤器运算符:
ngOnInit() {
this.accountService.getAll()
.pipe(
first(),
filter(e => e.role !== 'Admin'))
.subscribe(accounts => {
console.log(accounts);
this.accounts = accounts;
});
}
您可以轻松使用 JS 过滤器 function。 获取所有非管理员用户:
ngOnInit() {
this.accountService.getAll()
.pipe(first())
.subscribe(accounts => {
console.log(accounts);
this.accounts = accounts.filter((acct) => acct.role !== "Admin");
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.