str.indexOf vs str.includes

Benchmark created by Somename on


Setup

var stringArray = [
      'hello',
      'world',
      '123',
      'abc'
    ];

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
stringArray.some(function(val, idx, arr) {
  if (val.indexOf('world') !== -1) {
    return true;
  }
})
ready
includes
stringArray.some(function(val, idx, arr) {
  return val.includes('world')
})
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Somename on
  • Revision 2: published by darren on
  • Revision 4: published by TakeshiTanaka on