check if a element exists in array javascript
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!")
}
4
8
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.includes("Mango") // Returns true
Thank you!
8
0
Are there any code examples left?
New code examples in category Javascript