JS实现如何的统计一个字符串中相同的字符个数


 
 1          var string="start,stop,speed,start,speed,start,relocicty,start,start,start,start";
 2          var count=1;
 3          for (let index = 0; index < string.length; index++) {
 4             var a=string.indexOf("start",index);
 5              // console.log(a);
 6             if(a!=-1&&string.indexOf("start",index)!=string.indexOf("start",index-1)){
 7                  count++;
 8             }
 9          }
10          console.log(count);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM