Javascript: indexof details, examples and Applications

Source: Internet
Author: User

Javascript indexof

Returns the position of the substring that appears for the first time in the string object.

Javascript indexof format

Strobj. indexof (substring, start)

The strobj parameter is required. String object or text.

Substring is required. The substring to be searched by the indexof function in the string object.

Start is optional. This integer indicates the index in the string object. If it is omitted, It is searched from the first character of the string.

Note:

The indexof method returns an integer indicating the starting position of the substring in the string object. If no substring is found,-1 is returned. Javascript indexof functions are case sensitive.
 
 CodeExample:

1 < Script Type = " Text/JavaScript " >
2 VaR Str1 =   " Javascript indexof " ;
3 VaR S = Str1.indexof ( " Javascript " );
4   VaR S1 = Str1.indexof ( " Indexof " );
5   VaR S2 = Str1.indexof ( " Indexof " );
6 Document. Write ( " The position of Javascript in the string JavaScript indexof is <font color = Red> " );
7 Document. Write (s );
8 Document. Write ( " </Font> bit <br> " );
9  
10 Document. Write ( " The position of indexof in the string JavaScript indexof is <font color = Red> " );
11 Document. Write (S1 );
12 Document. Write ( " </Font> bit <br> " );
13  
14 Document. Write ( " The position of indexof in the string JavaScript indexof is <font color = Red> " );
15 Document. Write (S2 );
16 Document. Write ( " </Font> bit <br> " );
17 < / SCRIPT>
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.