Test name | Executions per second |
---|---|
find | 3133.5 Ops/sec |
For-loop | 3858.3 Ops/sec |
while | 3186.9 Ops/sec |
const arr = Array.from({ length: 20000 }, (_, i) => ({ property: i }))
const elementToFind = 15000;
const element = arr.find((el) => el.property === elementToFind);
const arr = Array.from({ length: 20000 }, (_, i) => ({ property: i }))
const elementToFind = 15000;
let element = undefined;
for (let i = 0; i < arr.length; i++) {
if (arr[i].property === elementToFind) {
element = arr[i];
break;
}
}
const arr = Array.from({ length: 20000 }, (_, i) => ({ property: i }))
const elementToFind = 15000;
let element = undefined;
let i = 0;
while(element === undefined) {
if(arr[i].property === elementToFind) {
element = elementToFind;
}
i++;
}