Being fairly new to Javascript, I'm unable to discern when to use each of these.
Can anyone help clarify this for me?
Being fairly new to Javascript, I'm unable to discern when to use each of these.
Can anyone help clarify this for me?
If you require a regular expression, use search(). Otherwise, indexof() is going to be faster.
The search function (one description here) takes a regular expression, which allows you to match against more sophisticated patters, case-insensitive strings, etc., while indexOf (one description here) simply matches a literal string. However, indexOf also allows you to specify a beginning index.
Search finds it's matches with a regular expression, but has no offsets. IndexOf uses literals to match, but has an offset.