<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>

 

效果图

 

posted on 2022-11-01 19:24  最帅爸爸  阅读(20)  评论(0)    收藏  举报