How to check if array has all elements of another array in TypeScript

2 Answers

0 votes
const arr1 = [22, 26, 1, 8, 18, 99, 71];
const arr2 = [22, 26, 1, 8, 18, 99, 71, 432, 310];

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, 71];
const arr2 = [22, 26, 1, 8, 18, 99, 71, 432, 310];

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

 



answered Jul 13, 2022 by avibootz
...