//1. Intercepting Strings varAA ="ABCD"; Console.log (Aa.substr (2,2)); varstr ="Qweda"; Console.log (Str.charat ()); //QConsole.log (Str.charat (0)); //QConsole.log (Str.charat (3)); //D//2. Determine the maximum number of characters in a string, and count the occurrences varstr ="Asdfaass"; varJSON = {};//Create a Hold object for(vari =0; i<str.length;i++) {//Traversing Strings if(!json[str.charat (i)]) {//determine if there are no function elements inside the objectJson[str.charat (i)] =1;//true to assign a value of 1}Else{Json[str.charat (i)]++;//fslse +1 and (replace the original value) } }; Console.log (JSON)varIMax =0;//Initialize varIIndex =""; for(varIinchJSON) { if(Json[i]>imax) {//Comparing maximum valuesIMax =Json[i]; IIndex=i; } } //Console.log (typeof (IMax) + "--" +typeof (IIndex));Console.log ("the most characters that appear are"+iindex+", the number of times is:"+IMax); //outerhtml varOdiv = document.getElementById ("Test"); Console.log (odiv.outerhtml); Console.log (odiv.innerhtml); //3, write a method to calculate the string varstr ="AA you good"; Console.log (Getstrlen (str)+"Get") function Getstrlen (str) {varJSON ={len:0}; varreg =/[\u4e00-\u9fa5]/;//regular Chinese characters for(vari =0; I < str.length;i++){ if(Reg.test (Str.charat (i))) {Json.len+=2; } console.log (JSON); }; returnjson.len+str.length; }//1. Intercepting Strings varAA ="ABCD"; Console.log (Aa.substr (2,2)); varstr ="Qweda"; Console.log (Str.charat ()); //QConsole.log (Str.charat (0)); //QConsole.log (Str.charat (3)); //D//2. Determine the maximum number of characters in a string, and count the occurrences varstr ="Asdfaass"; varJSON = {};//Create a Hold object for(vari =0; i<str.length;i++) {//Traversing Strings if(!json[str.charat (i)]) {//determine if there are no function elements inside the objectJson[str.charat (i)] =1;//true to assign a value of 1}Else{Json[str.charat (i)]++;//fslse +1 and (replace the original value) } }; Console.log (JSON)varIMax =0;//Initialize varIIndex =""; for(varIinchJSON) { if(Json[i]>imax) {//Comparing maximum valuesIMax =Json[i]; IIndex=i; } } //Console.log (typeof (IMax) + "--" +typeof (IIndex));Console.log ("the most characters that appear are"+iindex+", the number of times is:"+IMax); //outerhtml varOdiv = document.getElementById ("Test"); Console.log (odiv.outerhtml); Console.log (odiv.innerhtml); //3, write a method to calculate the string varstr ="AA you good"; Console.log (Getstrlen (str)+"Get") function Getstrlen (str) {varJSON ={len:0}; varreg =/[\u4e00-\u9fa5]/;//regular Chinese characters for(vari =0; I < str.length;i++){ if(Reg.test (Str.charat (i))) {Json.len+=2; } console.log (JSON); }; returnjson.len+str.length; }
JS face question-2