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