Test name | Executions per second |
---|---|
reversed for loop | 4873665.5 Ops/sec |
find method | 12336973.0 Ops/sec |
var array = [];
for (let i = 0 ; i < 10000 ; i++) {
array.push (Math.floor (Math.random () * 100));
}
const value = Math.floor (Math.random () * 100);
let found = undefined;
for (let i = array.length - 1 ; i >= 0 ; i--) {
if (array[i] === value) {
found = value;
break;
}
}
const value = Math.floor (Math.random () * 100);
let found = array.find ( (item) => item === value);