In JavaScript, 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?
If you require a regular expression, use search()
. Otherwise, indexOf()
is going to be faster.
indexOf
用于纯粹的子字符串, search
可以做正则表达式。
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.
链接地址: http://www.djcxy.com/p/216.html