if in array js 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: javascript is int in array
[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 4: how to check if item is in list js
var myList=["a", "b", "c"];
mylist.includes("d")//returns true or false
Example 5: javascript array contains
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
Example 6: js array includes
[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false
[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true
[1, 2, NaN].includes(NaN); // true