Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Search an Array for a Specific Value beyond Certain Index</title> </head> <body> <script> var arr = [1, 0, 3, 1, false, 5, 1, 4, 7]; // Searching forwards, starting at from- index document.write(arr.indexOf(1, 2) + "<br>"); // Prints: 3 // Searching backwards, starting at from index document.write(arr.lastIndexOf(1, 2)); // Prints: 0 </script> </body> </html>