javascriptstring

What is the difference between indexOf() and search()?


Being fairly new to JavaScript, I'm unable to discern when to use each of these.

Can anyone help clarify this for me?


Solution

  • If your situation requires the use of a regular expression, use the search() method, otherwise; the indexOf() method is more performant.