June 1, 2023
Program to use JavaScript String indexOf() method
let a = "JavaScript best programing language";
let b = a.indexOf("best");
console.log(b);
Output
11
Steps Description
- Declare two variable
a
andb
- Initialize two variable with value of string
a = "JavaScript best programing language"
andb
indexOf()
method will print the number of the index if the word or character is found in the string. will print -1 if not found- The value of
b
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript String indexOf() method example