JavaScript: indexOf vs. Match when Searching Strings?

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?

Leave a Comment