javascript check if array includes array code example

Example 1: angular one array contains any of second

const found = arr1.some(r=> arr2.includes(r))

Example 2: js test if array

if(Array.isArray(myVarToTest)) {
	// myVatToTest is an array
} else {
	// myVarToTest is not an array
}

Example 3: array includes

let storyWords = ['extremely', 'literally', 'actually', 'hi', 'bye', 'okay']
let unnecessaryWords = ['extremely', 'literally', 'actually' ];

let betterWords = storyWords.filter(function(word) {
  return !unnecessaryWords.includes(word);
});
console.log(betterWords) // ['hi' 'bye' 'okay]

Example 4: js array contains

let fruits = ["Banana", "Orange", "Apple", "Mango"];
let do_contain = fruits.includes("Mango"); // contain: true

Example 5: javascript check if in array

var extensions = ["image/jpeg","image/png","image/gif"];          
if(extensions.indexOf("myfiletype") === -1){
	alert("Image must be .png, .jpg or .gif");
}

Example 6: see if array contains array javascript

const found = arr1.some(r=> arr2.indexOf(r) >= 0)