JQuery obtains the maximum number of strings.

Source: Internet
Author: User

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.

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.