The Code is as follows: functionnumInstring (str) {strstr. replace (// ig, & quot;); varstrArrstr. split (& quot;); varresult [], beforeLength, afterLength, reg; for (vari0; I & lt; strArr.
The Code is as follows:
Function numInstring (str ){
Str = str. replace (// ig ,"");
Var strArr = str. split ("");
Var result = [], beforeLength, afterLength, reg;
For (var I = 0; I If (str. indexOf (strArr [I])! =-1 ){
BeforeLength = str. length;
Reg = new RegExp (strArr [I], "ig ");
Str = str. replace (reg ,"");
AfterLength = str. length;
Result. push (strArr [I] + ":" + (beforeLength-afterLength ));
}
}
Return result;
}
Var result = numInstring ("This section of the site is dedicated to the JavaScript language itself, the parts that are not specific to Web pages or other host ");
Console. log (result );
/* Result:
["T: 17", "h: 7", "I: 9", "s: 10", "e: 14", "c: 5", "o: 8 "," n: 3 "," f: 3 "," d: 3 "," a: 9 "," J: 1 "," v: 1 ", "r: 5", "p: 4", "l: 2", "g: 3", "u: 1", ",: 1", "W: 1 "," B: 1 "]
*/
Other methods: http://www.2cto.com/kf/201202/121035.html
From Artwl