实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p id="demo">Click the button to display the last position of the element "Apple", starting the search at position 4:</p>
6
7
<button onclick="myFunction()">Try it</button>
8
9
<script>
10
function myFunction()
11
{
12
var fruits=["Banana","Orange","Apple","Mango","Banana","Orange","Apple","Mango"];
13
var a=fruits.lastIndexOf("Apple",4)
14
var x=document.getElementById("demo");
15
x.innerHTML=a;
16
}
17
</script>
18
19
<p><b>Note:</b>The lastIndexOf method was introduced in JavaScript 1.6, and does not work in Internet Explorer 8 and earlier.</p>
20
21
</body>
22
</html>