Answers for "check if a element exists in array javascript"

5

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!")
    }
Posted by: Guest on April-16-2020
1

check if a element exists in array javascript

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.includes("Mango")   // Returns true
Posted by: Guest on August-04-2021

Code answers related to "check if a element exists in array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language