JavaScript String indexOf() method18 Mar 2025 | 2 min read The JavaScript string indexOf() method is used to search the position of a particular character or string in a sequence of given char values. This method is case-sensitive. The index position of first character in a string is always starts with zero. If an element is not present in a string, it returns -1. SyntaxThese are the following methods used to search the position of an element.
Parametersch - It represent the single character to search like 'a'. index - It represent the index position from where search starts. str - It represent the string to search like "Java". ReturnIndex of a particular character. JavaScript String indexOf() method exampleLet's see the various ways of searching the position of an element with help of simple examples. Example 1Here, we will print the position of a single character. Output: 2 Example 2In this example, we will provide the index value from where the search starts. Output: 7 Example 3Here, we will print the position of a first character of string. Output: 6 Example 4In this example, we will provide the index value from where the search starts. Output: 20 Example 5Here, we will try to search the element by changing its case-sensitivity. Output: -1 Next TopicJavaScript String |
JavaScript String Method The JavaScript string method is used to find out the primitive value of String object. This method is invoked by JavaScript automatically. Thus, there is no requirement to call it explicitly in the code. Syntax The method is represented by the following...
1 min read
JavaScript String Method The JavaScript string method is used to search the regular expression in the given string. This method returns -1, if match is not found. Syntax The method is represented by the following syntax: string.search(regexp) Parameter regexp - It represents the regular expression which is to...
1 min read
JavaScript String Method The JavaScript string method fetch the string on the basis of provided index and returns the new sub string. It works similar to the slice() method with a difference that it doesn't accepts negative indexes. This method doesn't make any change...
1 min read
JavaScript String Method The JavaScript string method is used to convert the string into lowercase letter. This method doesn't make any change in the original string. Syntax The method is represented by the following syntax: string. Return String in lowercase letter. JavaScript String Method Example Let's see some simple...
1 min read
JavaScript String Method The string method is an inbuilt method in JavaScript that joins two or more strings into a single string. In this article, we will learn how to efficiently utilize the method in different scenarios when programming in JavaScript. We will...
4 min read
JavaScript String Method JavaScript string method converts the string to uppercase letter on the basis of host's current locale. In most cases, this method returns the similar result as the toUpperCase() method. Syntax The method is represented by the following syntax: string. Returns A string of...
1 min read
JavaScript String Method The JavaScript string method is used to convert the string into uppercase letter. This method doesn't make any change in the original string. Syntax The method is represented by the following syntax: string. Return String in uppercase letter. JavaScript String Method Example Let's see some simple...
1 min read
JavaScript String Method The JavaScript string method is used to find out the Unicode value of a character at the specific index in a string. The index number starts from 0 and goes to n-1, where n is the length of the string. It returns...
1 min read
JavaScript String Method The JavaScript string method is used to replace a part of a given string with a new substring. This method searches for specified regular expression in a given string and then replace it if the match occurs. We can use global search...
2 min read
JavaScript String Method The JavaScript string method is used to find out a char value present at the specified index in a string. The index number starts from 0 and goes to n-1, where n is the length of the string. The index value can't...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India