📌  相关文章
📜  如何从 Javascript 中的过滤器返回特定值 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:28.632000             🧑  作者: Mango

代码示例1
//link
// https://stackoverflow.com/questions/57861821/how-to-return-specific-values-from-a-filter-in-javascript

var animals = [
 {id:1, name:"cat"}, 
 {id:2, name:"dog"}, 
 {id:3, name:"fish"}
];

var selected = [1,2];

var selectedAnimals = animals.filter(animal => selected.includes(animal.id));

console.log(selectedAnimals);