标签:索引 oct charset tle gyp 定义 new doc for
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>含a或A的字符</title>
</head>
<body>
<script>
//题目:统计含a 或者含 A 的字符串个数
//script中数组的用()or[]来定义。
var char=new Array("America","Greece","Britain","Canada","Chian","Egypt");
var num=0;
for (var i=0;i<char.length;i++){
//indexOf()方法,返回指定的字符串在字符串中首次出现的索引位置,如果没找到返回 -1 ;
if ((char[i].indexOf("a"||"A"))!=-1){
num++;
}
}
document.write(num);
</script>
</body>
</html>
标签:索引 oct charset tle gyp 定义 new doc for
原文地址:https://www.cnblogs.com/taoist123/p/11124794.html