Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set has vs object key vs in object
(version: 1)
performance comparison of ways to find if an array contains a value
Comparing performance of:
Includes vs Object[key] vs Set.has vs key in Object
Created:
11 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = (new Array(1000)).fill(null).reduce((prev, newVal) => {prev['__' + Math.random() + ''] = Math.random() + ''; return prev; }, { sausage: 'tst' }); var array = Object.keys(obj); var set = new Set(array);
Tests:
Includes
array.includes('sausage')
Object[key]
obj['sausage']
Set.has
set.has('sausage')
key in Object
('sausage' in obj)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Includes
Object[key]
Set.has
key in Object
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!
Comments
Confirm delete:
Do you really want to delete benchmark?