14.
Which JavaScript String method is used to find the index of a specified value within a string and return the index position?
toLowerCase()
substr()
replace()
indexOf()
Correct: D
The indexOf() method is used to find the index position of the first occurrence of a specified value within a string. It returns -1 if the value is not found. For example, "Hello, world!".indexOf("o") would return 4, since the letter "o" is first found at index position 4 in the string.
const string = "Hello, world!";
const index = string.indexOf("o");
console.log(index); // Output: 4