Introduction to JavaScript LastIndexOf method (calculates where the specified character last appears in the string) _ Basics

Source: Internet
Author: User

JavaScript LastIndexOf method

The LastIndexOf method computes the last occurrence of the specified string in the entire string and returns the value. The syntax is as follows:

Copy Code code as follows:

Str_object.lastindexof (search, start)

Parameter description:

Parameters Description
Str_object The string to manipulate (object)
Search Necessary. The string to retrieve
Start Optional. Specifies the location at which to start retrieving, such as omitting the argument, and then starting from the last character of the string

Tip: The string is counted starting from 0.

LastIndexOf Method Instance

Copy Code code as follows:

<script language= "JavaScript" >

var str = "Www.jb51.net";
document.write (Str.lastindexof (".") + "<br/>");
document.write (Str.lastindexof (".", 5) + "<br/>");
document.write (Str.lastindexof (".", 10));

</script>

Run the example and output:

Copy Code code as follows:

9
3
9



Note that in the example above, the second parameter is 5, the first one is actually found. Symbol, that is, searching in the www.5 string.


LastIndexOf is case sensitive, and if the string value to retrieve does not appear, the method returns-1.

Related Article

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.