Skip to content

Fastest method for Javascript substring search

I have a mobile application that needs to search through a rather large array and I’m experiencing some optimization issues with it.  So, I decided to run some tests to see which function would be the fastest between indexOf, search, and includes.

I first tested all three with a static search value, search performed the best:

test1

But, with a variable, indexOf performed the best:

test2

I was able to perform these tests pretty easily using https://jsperf.com/ 🙂

Published inJavaScriptScripting

Be First to Comment

Leave a Reply

Your email address will not be published.