简单教程
提交运行
代码编辑器:
<p id="demo">单击按钮显示“苹果”最后一次出现的位置:</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var fruits=["Banana","Orange","Apple","Mango","Banana","Orange","Apple","Mango"]; var a=fruits.lastIndexOf("Apple") var x=document.getElementById("demo"); x.innerHTML=a; } </script> <p><b>注意:</b>lastIndexOf方法在JavaScript 1.6被引进,在Internet Explorer 8或更早的版本中不支持</p>
运行结果: