Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to filter an array by list of objects in javascript

var array = ['Jane','Donna','Jim','Kate']
var objects = [{name:'Jane', age:25},{name:'Jim', age:30}]

//finds the items in the array that have names within the array of objects.
var filtered = array.filter(r => objects.findIndex(obj => obj.name == r) > -1 )
console.log(filtered)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #filter #array #list #objects #javascript
ADD COMMENT
Topic
Name
9+5 =