- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- 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
- Removing first occurrence of specified value from LinkedList in C#
- Get the first occurrence of a substring within a string in Arduino
- How to count the occurrence of a specific string in a string in JavaScript
- Index of first occurrence in StringCollection in C#?
- How to get the primitive value of string in Javascript?
- Finding the index of the first repeating character in a string in JavaScript
- How to get a part of string after a specified character in JavaScript?
- How to find index of last occurrence of a substring in a string in Python?
- Get the substring after the first occurrence of a separator in Java
- Return index of first repeating character in a string - JavaScript
- How to get a number value of a string in Javascript?
- First occurrence in the List that matches the specified conditions in C#
- How is it possible in MySQL to find the location of the first occurrence of a substring in a string?

Advertisements