Which string method returns the index of the first occurrence of a substring, or -1 if not found?

JavaScript Associate Easy

JavaScript Associate — Easy

Which string method returns the index of the first occurrence of a substring, or -1 if not found?

Key points

  • indexOf() returns the index of the first occurrence of a substring.
  • If the substring is not found, indexOf() returns -1.
  • search() and find() are similar but do not return the index.
  • includes() checks if a substring is present, but does not return the index.

Ready to go further?

Related questions