Answers for "How to Return Specific Values from a Filter in Javascript"

0

How to Return Specific Values from a Filter in Javascript

//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);
Posted by: Guest on July-27-2021

Code answers related to "How to Return Specific Values from a Filter in Javascript"

Browse Popular Code Answers by Language