我有用户
列表:
users: Array<any> = [{id:1,name:'A'},{id:2,name:'B'},{id:3,name:'C'}];
和
this.selectedUsers = [1,2];
如何从 users
数组中获取在 selectUsers
数组中找到的 id
的所有对象?
最佳答案
您可以将 indexOf 与过滤器一起使用。
this.users.filter(user => this.selectedUsers.indexOf(user.id ) > -1)
关于javascript - 基于 id 列表从对象中获取值的有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42385415/