function countNumber(str) { var sum = 0; //计数变量 var arr = str.split('') for ( i = 0 ; i < arr.length; i++ ){ //遍历数组 sum++;//自加 } console.log(sum) } var oldStr = countNumber('Rome was not built in a day');