indexOf 返回字符串中指定字符首次出现的位置

  var str="hello, I am Miss bean!";

  str.indexOf("l")//结果为2

indexOf('l',2) //表示从第2位开始查找l元素首次出现的位置

1 var str="hello, I am Miss bean!";
2     console.log(str.indexOf('l'));//结果2
3     console.log(str.indexOf('l',3));//结果3
4     console.log(str.indexOf('s'));//结果14
5     console.log(str.indexOf('s',15));//结果15

 

相关文章:

  • 2022-03-06
  • 2022-03-05
  • 2022-12-23
  • 2021-11-26
猜你喜欢
  • 2021-10-11
  • 2021-08-10
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案