Array.indexOf()

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript Array.indexOf()</h1>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. var fruits = ["Apple", "Orange", "Apple", "Mango"];
  11. var a = fruits.indexOf("Apple");
  12. document.getElementById("demo").innerHTML = "Apple 被找到的位置是:" + (a + 1);
  13. </script>
  14.  
  15. <p>Internet Explorer 8 或更早的版本不支持 indexOf()。</p>
  16.  
  17. </body>
  18. </html>