Multiple choice

Which of the following function returns the position of a specified character in a String?

  1. charAt

  2. indexOf

  3. valueOf

  4. substring

  5. match

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The indexOf() returns the index or position of a character or a string in the given string. The indexOf() returns -1 is the searched character is not found. For example in the following codevar str="aliensbrain.com"; var n=str.indexOf("l");The value of 'n' will be '2' since it is the 2nd character in the string starting from 0.