Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array indexOf vs includes vs some vs for
(version: 0)
performance comparison of ways to find if an array contains a value
Comparing performance of:
IndexOf vs Includes vs some vs for
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var array = ['banana', 'sausage', 'jesus']
Tests:
IndexOf
x = false; if(array.indexOf('sausage') !== 1){ x = true; }
Includes
x = false; if(array.includes('sausage')){ x = true; }
some
x = false; if(array.some(v => v === 'sausage')){ x = true; }
for
x = false; for(let i=0; i < array.length; i++){ if(array[i] === 'sausage'){ x = true; break; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
IndexOf
Includes
some
for
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0
Browser/OS:
Firefox 119 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
IndexOf
55164928.0 Ops/sec
Includes
48754256.0 Ops/sec
some
144918208.0 Ops/sec
for
177091808.0 Ops/sec
Related benchmarks:
IndexOf vs Includes
array indexOf vs includes vs some
array indexOf vs includes vs some aaa
array indexOf vs includes vs some 4 elements
array indexOf vs includes vs some corrected
Comments
Confirm delete:
Do you really want to delete benchmark?