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

Your email address will not be published. Required fields are marked *

You May Also Like

JavaScript supports different types of operators that includes Assignment Operator JavaScript supports different types if Assignment Operators like = +=...
Assume that you have an angle in degree and you wish to convert it to radians in JavaScript so that...
The JavaScript elements and statements are placed within the script tag within the HTML page. You can specify the language...