Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
Firefox 107
Windows
Desktop
one year ago
Test name Executions per second
findIndex 8137.9 Ops/sec
for loop 38943.2 Ops/sec
Script Preparation code:
AخA
 
var arr = new Array(15000);
arr.fill({ id: 0 });
arr = arr.map((el, idx) => el.id = idx);
var foo = Math.floor(Math.random() * 15000);
Tests:
  • findIndex

     
    arr.findIndex((itm) => itm.id === foo);
  • for loop

     
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].id === foo) break;
    }