JS find the location and number of times a character appears in a string

var STR = 'fdhfgcsaedvcfhgfh' ;
 var index = str.indexOf ( 'F'); // position of a character appearing 
var NUM = 0; // the number of characters that appear in 
the while (! index == -1 ) { 
    the console.log (index); // position of the print string that appears 
    NUM ++; // each occurrence frequency and a plus 
    index = str.indexOf ( 'F',. 1 + index); // start at the next occurrence of the string position continues to look 
} 
the console.log ( 'F appeared in a total' + num + 'views');
str.inedxOf ( 'string to look', the starting position);

Guess you like

Origin www.cnblogs.com/sunyan-blog/p/11783408.html