Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript find elements in array that matches another array

let haveItList = ['apples', 'milk', 'bread', 'peanutbutter'];
let wishList = ['cookies', 'bread', 'jam', 'peanutbutter', 'bananas', 'cheese'];

let inBothLists = wishList.filter(element => haveItList.includes(element));
// inBothLists = ['apples', 'bread', 'peanutbutter'];
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #JavaScript #find #elements #array #matches #array
ADD COMMENT
Topic
Name
8+1 =