Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if first array contains all elements javascript

// Not Supported in IE 9-11
const arr1 = ['pizza', 'cola'];
const arr2 = ['pizza', 'cake', 'cola'];

const containsAll = arr1.every(element => {
  return arr2.includes(element);
});

console.log(containsAll); // true


// Supported in IE 9-11
const arr1 = ['pizza', 'cola'];
const arr2 = ['pizza', 'cake', 'cola']

const containsAll = arr1.every(element => {
  return arr2.indexOf(element) !== -1;
});

console.log(containsAll); // true
 
PREVIOUS NEXT
Tagged: #check #array #elements #javascript
ADD COMMENT
Topic
Name
7+6 =