Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #Return #Specific #Values #Filter #Javascript
ADD COMMENT
Topic
Name
6+4 =