javascript if in array code example
Example 1: javascript array contains
var colors = ["red", "blue", "green"];
var hasRed = colors.includes("red");
var hasYellow = colors.includes("yellow");
Example 2: typescript check if element in array
your_array.includes(the_element)
Example 3: js test if array
if(Array.isArray(myVarToTest)) {
} else {
}
Example 4: javascript is int in array
[1, 2, 3].includes(2);
[1, 2, 3].includes(4);
[1, 2, 3].includes(1, 2);
Example 5: how to check if item is in list js
var myList=["a", "b", "c"];
mylist.includes("d")
Example 6: javascript array contains
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");