<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>
效果图
标签:下标,console,log,indexOf,list,yellow,LastIndexOf From: https://www.cnblogs.com/zsbb/p/16848879.html