Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36
Chrome 95
Mac OS X 10.15.7
Desktop
3 years ago
Test name Executions per second
indexOf 12769638.0 Ops/sec
includes 13762992.0 Ops/sec
lodash 3628653.2 Ops/sec
for 731445888.0 Ops/sec
Script Preparation code:
AخA
 
var array = ['banana', 'sausage', 'jesus']
Tests:
  • indexOf

     
    array.indexOf('sausage') !== 1
  • includes

     
    array.includes('sausage')
  • lodash

     
    _.includes(array, 'sausage')
  • for

     
    const inArray = (target = 'sausage', array) => {
      for(let i = 0; i < array.length; i++) {
        if(array[i] === target) {
          return true;
        }
      }
      return false; 
    }