Walkthrough of JavaScript IndexOf Method (calculates where the specified character first appears in the string) _ Basics

Source: Internet
Author: User

JavaScript IndexOf method

The IndexOf method computes the first occurrence of a specified string in a string and returns that value. The syntax is as follows:

Copy Code code as follows:

Str_object.indexof (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 starting from the first character of the string

Tip: The string is counted starting from 0.

IndexOf Method Instance

Copy Code code as follows:

<script language= "JavaScript" >

var str = "Www.jb51.net";
document.write (Str.indexof ("."));

</script>

Run the example and output:

Copy Code code as follows:

3

IndexOf 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.