<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var str = "abcdefghelloworldsheep"
var index = str.indexOf('o');
var num = 0;
while(index !== -1) {
console.log(index);
num++;
index = str.indexOf('o',index+1);
}
console.log('o出现的次数为' + num);
</script>
</head>
<body>
</body>
</html>
查找某个字符串中某个字符出现的次数
最新推荐文章于 2023-12-06 17:49:45 发布