indexOf & lastIndexOf to get location of a string

<script type="text/javascript">
var my_str=""
The above code will return 4

We can find out the location of a particular string inside the main string by using indexOf function.

The first character of the main string is considered as 0 location.

We will get the position of first occurrence of the matching string.
document.write(my_str.indexOf(".")// Output is 3)


This method returns us the last occurrence of the string from the left and the location ( or position ) is given from starting ( left ) side.

Here is the code.
var my_str="Welcome to"
Output of above code is 16 as l position is counted up to the last occurrence.
JavaScript String Reference IndexOf is used to get domain name userid from email address
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer