JQuery obtains the maximum number of strings.
Recommended reading:A tool used to count the number of occurrences of each string in jQuery.
I don't need to talk much about it. I just paste JavaScript code to you.
// Obtain the maximum number of occurrences of a string and the total number of occurrences of the string var str = 'asdfssaaasasasasasa'; // define the string var json = {}; // define an array to store the numbers corresponding to each character element (var I = 0; I <str. length; I ++) {// traverse all elements of the string if (! Json [str. charAt (I)]) {// checks whether the current element already exists in the array. charAt (I) // The current element json [str. charAt (I)] = 1; // assign a value to the number of corresponding array elements} else {json [str. charAt (I)] ++; // assign a value to the number of elements in the array }}; var iMax = 0; // number of occurrences var iIndex = ''; // element name for (var I in json) {// returns the most data and number of values if (json [I]> iMax) {iMax = json [I]; iIndex = I ;}// alert ('the most appears: '+ iIndex +' + iMax + '');
The above code is the most frequently-seen Number of jQuery strings introduced by xiaobian. The code is easy to understand. If you do not understand anything, please leave a message. I will contact you in time.
Articles you may be interested in:
- A tool used to count the number of occurrences of each string in jQuery.