Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Check if an Element is Present in an Array in JavaScript</title> </head> <body> <script> var fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya"]; // Check if a value exists in the fruits array if(fruits.indexOf("Mango") !== -1){ document.write("Value exists!") } else{ document.write("Value does not exists!") } </script> </body> </html>