Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if array contain the all element javascript

const myArray: number[] = [2, 4, 6, 8, 10, 12, 14, 16];
const elements: number[] = [4, 8, 12, 16];

function containsAll(arr: number[]) {
  return (
    arr.includes(elements[0]) &&
    arr.includes(elements[1]) &&
    arr.includes(elements[2]) &&
    arr.includes(elements[3])
  );
}
console.log(containsAll(myArray));

or you could use the following line:

function c2(arr: number[]) {
  return elements.every((val: number) => arr.includes(val));
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: shift and unshift js 
Javascript :: return inside for loop javascript 
Javascript :: window.location.origin 
Javascript :: get total pairs from integer array javascript 
Javascript :: parsing json object in java 
Javascript :: node cron install 
Javascript :: js round 2 decimals 
Javascript :: angular injectiontoken 
Javascript :: javascript string add new line 
Javascript :: use filereader javascript 
Javascript :: jquery slider move event 
Javascript :: export function node js 
Javascript :: Using flat() method 
Javascript :: how to run node js with proxy 
Javascript :: how to get value inside span using javascript 
Javascript :: how to use buffer in angular by using browserify 
Javascript :: order by mongodb 
Javascript :: javascript get clock time in auto counter up 
Javascript :: js json escape 
Javascript :: queryselectors select element whole class 
Javascript :: nuxt get client windows size 
Javascript :: best node js orm for mysql 
Javascript :: run node script pupeeter when button from form clicked 
Javascript :: deno vs nodejs 
Javascript :: jquery ajax send custom data after serialize 
Javascript :: react-google-login 
Javascript :: how to convert string to number in javascript 
Javascript :: nuxtjs loading 
Javascript :: react navbar material ui 
Javascript :: lastindexof 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =