Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find in array - 002
(version: 1)
Comparing performance of:
For i++ (const size) vs For i++ (.length) vs For ... in vs for ... of vs indexOf vs findIndex vs Includes vs Some ? vs forEach
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var size = 10000 var arr = [] for (let i = 0; i < size; i++) { arr.push(i) } var research = 6578;
Tests:
For i++ (const size)
const a_size = arr.length; var index = -1; for (let y = 0; y < a_size; y++) { if (research === arr[y]) { index = y; break; } }
For i++ (.length)
var index = -1; for (let y = 0; y < arr.length; y++) { if (research === arr[y]) { index = y; break; } }
For ... in
var index = -1; for (const y in arr) { if (research === arr[y]) { index = y; break; } }
for ... of
var index = -1; for (const el of arr) { if (research === el) { index = el; break; } }
indexOf
var index = arr.indexOf(research)
findIndex
var index = arr.findIndex(e => e === research)
Includes
var found = arr.includes(research)
Some ?
var found = arr.some(e => e === research)
forEach
var index = -1; arr.forEach((el, y) => { if (research === el) { index = y; return; } })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (9)
Previous results
Fork
Test case name
Result
For i++ (const size)
For i++ (.length)
For ... in
for ... of
indexOf
findIndex
Includes
Some ?
forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
array last element big data
Test array and unshift
Speed of Arr.length and Slice
Getting last element of array
Array last index
Comments
Confirm delete:
Do you really want to delete benchmark?