How to use JavaScript String indexOf()

Program to use JavaScript String indexOf() method

let a = "JavaScript best programing language";

let b = a.indexOf("best");




Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of string a = "JavaScript best programing language" and b
  3. 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
  4. The value of b variable is displayed with the help of console.log inbuilt function