Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: Getting The Search Params With A For Of Loop 
Javascript :: Using an object of functions as a parameter into a function 
Javascript :: A Method In Class That Accesses A Property 
Javascript :: javascript hide div 
Javascript :: jquery properties 
Javascript :: path.join javascript one folder above 
Javascript :: jQuery mobile anchor link on the same page 
Javascript :: prevent the Confirm Form Resubmission dialog | window.history.back() confirm form resubmission 
Javascript :: onclick readmore and readless react js 
Javascript :: problem with Next.js and @material-ui. 
Javascript :: var logEvenNums = function(num) {}; 
Javascript :: expact 
Javascript :: Update react final form field 
Javascript :: Different Pages For Different Routes In Backbone 
Javascript :: react private routes 
Javascript :: create number format excel react native 
Javascript :: jquery try catch 
Javascript :: insert element in array javascript 
Javascript :: fs 
Javascript :: javascript oop 
Javascript :: react color picker 
Javascript :: angular cli command to create component without spec 
Javascript :: calculate jwt expire time 
Javascript :: how to add prefix to a string in javascript 
Javascript :: react native android build location 
Javascript :: java script layout engine error 
Javascript :: javascript copy array using spread operator 
Javascript :: random number 1-3 
Javascript :: node js - excecute a child process and exchange message to and from 
Javascript :: js regex find newlines 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =