
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the first index of an occurrence of the specified value in a string in JavaScript?
To get the first index of an occurrence of the specified value in a string, use the JavaScript indexOf() method.
Example
You can try to run the following code to get the first index −
<html> <head> <title>JavaScript String indexOf() Method</title> </head> <body> <script> var str = new String( "Learning is fun! Learning is sharing!" ); var index = str.indexOf( "Learning" ); document.write("First index of string Learning :" + index ); </script> </body> </html>
- Related Questions & Answers
- How to get the last index of an occurrence of the specified value in a string in JavaScript?
- Get the index of the first occurrence of a separator in Java
- Get the first occurrence of a substring within a string in Arduino
- Removing first occurrence of specified value from LinkedList in C#
- Finding the index of the first repeating character in a string in JavaScript
- Index of first occurrence in StringCollection in C#?
- Get the substring after the first occurrence of a separator in Java
- How to get the primitive value of string in Javascript?
- How to count the occurrence of a specific string in a string in JavaScript
- Getting index of the specified value in a SortedList object in C#
- How to get the first n values of an array in JavaScript?
- How to get only the first n% of an array in JavaScript?
- Getting the value at the specified index of a SortedList object in C#
- Return index of first repeating character in a string - JavaScript
- How is it possible in MySQL to find the location of the first occurrence of a substring in a string?
Advertisements