Javascript search() String Method

Last Updated Jul 29, 2015, 07:00:14 PM

The javascript string search() method executes the search for a match between a regular expression and this String object.

Argument Details


A regular expression object. If a non-RegExp object obj is passed, it is implicitly converted to a RegExp by using new RegExp(obj).

when using the search() method, if the search finds the pattern, it returns the index of the first match otherwise it returns -1 which indicates as not found.


In the above example, it will try to search the word Sunday in the given string called var, and it will return some message otherwise it returns -1

Try It Now

Sources and Credits

The source of the content has been referred and updated with Mozilla Developer Network and W3C Organization

Last Updated Jul 29, 2015, 07:00:14 PM

Browser compatibility

indexOf() Yes Yes Yes Yes Yes Yes Yes