源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>JavaScript 数组</h1> <h2>lastIndexOf() 方法</h2> <p>lastIndexOf() 指定元素的最后一个索引值:</p> <p id="demo"></p> <script> const fruits = ["Apple", "Orange", "Apple", "Mango"]; let index = fruits.lastIndexOf("Apple"); document.getElementById("demo").innerHTML = index; </script> </body> </html>
运行结果: