在JavaScript中,indexOf()和search()之间有什么区别?
问题描述:
作为JavaScript的新手,我无法辨别何时使用这些内容。
Being fairly new to JavaScript, I'm unable to discern when to use each of these.
任何人都可以帮我澄清一下吗?
Can anyone help clarify this for me?
答
如果需要正则表达式,请使用 search()
。否则, indexOf()
会更快。
If you require a regular expression, use search()
. Otherwise, indexOf()
is going to be faster.