JS Face question-2

Source: Internet
Author: User

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.