Search for a String using JavaScript indexof method

The indexof method in JavaScript is used to search a string from the given input string. I returns the position of the first occurrence of the specified string in the input string. If the value is not found , it returns -1 . Also note that the indexof method is case sensitive.

How to Search for a String using JavaScript indexof method ?

Below is a sample code snippet demonstrating how to search for a string using js indexof method.

var input = "This is a blog post.";
var value = str.indexOf("");

The result of value will be 10.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


Interesting BlogPosts to read

How to print title on every page in Microsoft Excel?
Most of the time we might end up having a long workbook with huge amount of data and they have lot o...
How to quickly remove multiple line breaks in Excel using VBA code?
There are times when you might copy few data from different source and you would end up getting unne...
How to change orientation of the worksheets in Microsoft Excel ?
This blog post will show the steps that are needed to change the orientation of the current workshee...