Array.lastIndexOf()

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