Finding Elements

Benchmark published by System on

Description

Compare indexOf vs find vs findIndex.

Setup

const arr = Array.from({length: 10000}, (_, i) => ({ id: i, value: 'val' + i }));
const target = 5000;

Test Runner

Initializing...

Testing in
Test CaseOps/sec
findIndex
arr.findIndex(item => item.id === target);
ready
find
arr.find(item => item.id === target);
ready
for loop
let found;
for(let i=0; i<arr.length; i++) {
  if (arr[i].id === target) { found = arr[i]; break; }
}
ready

Revisions

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

Revision 1
publishedby Systemon