HomeJavaScriptSearch for a String using JavaScript indexof method

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 Ginktage.com blog post.";
var value = str.indexOf("Ginktage.com");

The result of value will be 10.

Leave a Reply

You May Also Like

You might want to filter an array in JavaScript by passing the filter criteria and return the filtered array. In...
You can flatten a 2-D array in JavaScript using the concat and apply method as shown in the below code...
Assume that you have an angle in degree and you wish to convert it to radians in JavaScript so that...