Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Chrome 103
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
Array.some 279947.7 Ops/sec
Array.filter 88366.6 Ops/sec
Array.findIndex 252965.1 Ops/sec
Script Preparation code:
AخA
 
var hasZero = [];
var withoutZero = [];
for (var i = 0; i < 10000; i++) {
  hasZero.push(Math.floor(Math.random() * 1000));
  withoutZero.push(Math.floor(Math.random() * 1000) + 1)
}
Tests:
  • Array.some

     
    var tempResult = !!Math.round(Math.random()) ? hasZero.some(v => v === 0) : withoutZero.some(v => v === 0);
  • Array.filter

     
    var tempResult = !!Math.round(Math.random()) ? hasZero.filter(v => v === 0) : withoutZero.filter(v => v === 0);
  • Array.findIndex

     
    var tempResult = !!Math.round(Math.random()) ? hasZero.findIndex(v => v === 0) : withoutZero.findIndex(v => v === 0);