How to check if array has all elements of another array in Node.js

2 Answers

0 votes
const arr1 = [22, 26, 1, 8, 18, 99, 39];
const arr2 = [22, 26, 1, 8, 18, 99, 39, 761, 509];

console.log(arr1.every(element => { return arr2.includes(element); }));
   
   
    
    
/*
run:
    
true
  
*/

 



answered Jul 13, 2022 by avibootz
0 votes
const arr1 = [22, 26, 1, 8, 18, 99, 39];
const arr2 = [22, 26, 1, 8, 18, 99, 39, 761, 509];

console.log(arr1.every(r=> arr2.indexOf(r) >= 0));
   
   
    
    
/*
run:
    
true
  
*/

 



answered Jul 13, 2022 by avibootz

Related questions

...