js--输入一个字符串,统计字符串中有多少个大写字母,小写字母,数字,空格,其他字符

	var str = "123AAbbb  !@#$";
	var count1 = 0;
	var count2 = 0;
	var count3 = 0;
	var count4 = 0;
	var count5 = 0;
for(var i=0; i= 'A' && str.charAt(i) <= 'Z'){
		count1++;
	}else if(str.charAt(i) >= 'a' && str.charAt(i) <= 'z'){
		count2++;
	}else if(str.charAt(i) >= '0' && str.charAt(i) <= '9'){
		count3++;
	}else if(str.charAt(i) == " "){
		count4++;
	}else{
		count5++;
	}
}

console.log(count1,count2,count3,count4,count5);

 

你可能感兴趣的:(web前端小白)