How to use jquery indexof _jquery

Source: Internet
Author: User
IndexOf () and LastIndexOf () is the use of JS, and jquery is irrelevant, all directly with the original JS can be.

The IndexOf () and LastIndexOf () methods return the position of the specified substring in another string, or 1 if no substring is found.
The difference between the two methods is that the IndexOf () method retrieves the string starting at the beginning of the string (position 0), and the LastIndexOf () method retrieves the substring starting at the end of the string.

Strobj.indexof (substring[, StartIndex]) parameter strobj required option. A String object or text. subString required option. The substring to find in the string object. Starindex can be selected. An integer value that indicates the index in which to start the lookup within a String object. If omitted, it is looked up from the beginning of the string.

Explains that the IndexOf method returns an integer value that indicates the start position of the substring of a string object. If no substring is found, returns-1. If the startindex is a negative number, the startindex is treated as zero. If it is larger than the maximum character position index, it is considered to be the largest possible index. Performs a lookup from left to right. Otherwise, the method is the same as LastIndexOf.

Example: [code_html] [/code_html] The final result is -1,0,3

if (Ss.indexof (' winner ') >-1)
Strobj.indexof (substring[, startindex])
Where Strobj is a required option. String object or text

Copy Code code as follows:

<script type= "Text/javascript" >
array.prototype.indexOf = function (str) {
for (var i = 0; i < this.length; i++) {
if (str = = This[i]) {
return i;
}
}
return-1;
}
</script>

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.