check if an array has an element javascript code example
Example 1: javascript check if is array
var colors=["red","green","blue"];
if(Array.isArray(colors)){
//colors is an array
}
Example 2: typescript check if element in array
your_array.includes(the_element)
Example 3: javascript method to see if item exists in array
var fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya"];
// Check if a value exists in the fruits array
if(fruits.indexOf("Mango") !== -1){
alert("Value exists!")
} else{
alert("Value does not exists!")
}