Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Search an Array for a Specific Value</title> </head> <body> <script> let fruits = ["Apple", "Banana", "Mango", "Orange", "Papaya"]; document.write(fruits.indexOf("Apple") + "<br>"); // Prints: 0 document.write(fruits.indexOf("Banana") + "<br>"); // Prints: 1 document.write(fruits.indexOf("Pineapple")); // Prints: -1 </script> </body> </html>