SS+=+'IiFe+s+hort,+i+use+PYtHon'+定义一个函数统计字符串i或I出现的次数
时间: 2023-12-13 17:05:56 浏览: 127
origamid-[removed]JavaScript ES6 + | 从基本到精通的语言
以下是统计字符串中i或I出现次数的函数:
```javascript
function countI(str) {
let count = 0;
for (let i = 0; i < str.length; i++) {
if (str[i] === 'i' || str[i] === 'I') {
count++;
}
}
return count;
}
let SS = 'IiFe+s+hort,+i+use+PYtHon';
console.log(countI(SS)); // 输出:5
```
阅读全文