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

上一篇: 如何检查数组是否包含JavaScript中的对象?

下一篇: 在JavaScript中,indexOf()和search()有什么区别?