[removed] indexOf vs. Match when Searching Strings?

前端 未结 9 1593
感情败类
感情败类 2020-12-04 13:16

Readability aside, are there any discernable differences (performance perhaps) between using

str.indexOf("src") 

and



        
9条回答
  •  余生分开走
    2020-12-04 13:38

    RegExp is indeed slower than indexOf (you can see it here), though normally this shouldn't be an issue. With RegExp, you also have to make sure the string is properly escaped, which is an extra thing to think about.

    Both of those issues aside, if two tools do exactly what you need them to, why not choose the simpler one?

提交回复
热议问题