javascript string in array code example

Example 1: javascript element in array

var fruits = ["Banana", "Orange", "Apple", "Mango"];

var n = fruits.includes("Mango");

Example 2: javascript list include

const array1 = [1, 2, 3];

console.log(array1.includes(2));
// expected output: true

const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// expected output: true

console.log(pets.includes('at'));
// expected output: false

Example 3: see if array contains array javascript

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

Example 4: array of in javascript

The Array. of() method creates a new Array instance from a variable number of 
arguments, regardless of number or type of the arguments. The difference between
Array. of() and the Array constructor is in the handling of integer arguments: Array.