javascript not in array code example

Example 1: javascript array contains

var colors = ["red", "blue", "green"];
var hasRed = colors.includes("red"); //true
var hasYellow = colors.includes("yellow"); //false

Example 2: typescript check if element in array

your_array.includes(the_element)

Example 3: check if array has same values javascript

const allEqual = arr => arr.every(v => v === arr[0]);
allEqual([1,1,1,1]);  // true

Example 4: in javascript check is is an array or not

Array.isArray(yourItem)

Example 5: check value exist in array javascript

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, 3].includes(1, 2);  // false (second parameter is the index position in this array at which to begin searching)

Example 6: not in array js

!array.includes("element")

Tags:

Vb Example