search()
accepts a regular expression as the argument.
search()
method returns the index of the first
pattern occurrence in the string.
search()
returns -1 if not found.
search() |
Yes | Yes | Yes | Yes | Yes |
string.search(aValue);
Parameter | Description |
---|---|
aValue | Required. A regular expression. |
Return the position of the first occurrence of the specified aValue.
Or -1 if no match is founds.
var text = "loom, room, doom";
var pos = text.search(/asdf/);
console.log(pos); //-1
The code above generates the following result.