A simple example of determining the maximum number of characters and the number of occurrences of a string in JS. js string
A simple example of determining the maximum number of characters and the number of occurrences of a string in JS
<Script type = "text/javascript"> var str = 'qwertyuilo ., mnbvcsarrrrrrtyuiop; l, mhgfdqrtyuio ;. cvxsrtyiuo '; var json ={}; // traverses str and disconnects each character to take out the value and number of occurrences of a specific character as the json kv for (var I = 0; I <str. length; I ++) {// determines whether the current str value exists in json if (! Json [str. charAt (I)]) {// Add the current value to json if it does not exist [str. charAt (I)] = 1;} else {// else, the index value of the existing value in the array will be +; json [str. charAt (I)] ++ ;}// store the maximum number of occurrences and times var number = ''; var num = 0; // traverse json and use the hitting algorithm to calculate the required value for (var I in json) {// if the current item is greater than the next if (json [I]> num) {// change the current value to the value num = json [I]; number = I ;}} // print the maximum number of occurrences and the number of occurrences of alert ('the maximum number of occurrences is '+ number +' and the number of occurrences is '+ num); </script>
A simple example of judging the most frequently occurring characters and the number of occurrences of a string in the above JS is all the content shared by xiaobian. I hope you can give me a reference, we also hope that you can support the customer's home.