<script>
//首次出现o的下标索引位置
console.log("helloIndexof".indexOf("o"))
//最后一次出现o的下标索引位置
console.log("helloIndexof".lastIndexOf("o"))
//在数组中首次出现的下标索引位置
let list=["yellow","blue","green","yellow","blue","green"]
console.log(list.indexOf("yellow"))
//还可以指定从哪位查起
console.log(list.indexOf("yellow",2))
//最后一次出现的下标索引文字
console.log(list.lastIndexOf("yellow"))
</script>
效果图

本文来自博客园,作者:最帅爸爸,转载请注明原文链接:https://www.cnblogs.com/zsbb
浙公网安备 33010602011771号