Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for-in vs object.keys vs object.values vs arr
(version: 0)
Comparing performance of:
for-in vs Object.keys vs Object.values vs Array for vs Array forEach
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = { 'a': { id: 'a', num: 1 }, 'b': { id: 'b', num: 1 }, 'c': { id: 'c', num: 1 }, 'd': { id: 'd', num: 1 }, 'e': { id: 'e', num: 1 }, 'f': { id: 'f', num: 1 }, 'g': { id: 'g', num: 1 }, }; var arr = [ { id: 'a', num: 1 }, { id: 'b', num: 1 }, { id: 'c', num: 1 }, { id: 'd', num: 1 }, { id: 'e', num: 1 }, { id: 'f', num: 1 }, { id: 'g', num: 1 } ];
Tests:
for-in
for (var i=10000; i > 0; i--) { for (var key in obj) { console.log(obj[key].id); } }
Object.keys
for (var i=10000; i > 0; i--) { Object.keys(obj).forEach(key => console.log(obj[key].id)); }
Object.values
for (var i=10000; i > 0; i--) { const values = Object.values(obj); for (var j=0,l=values.length; j < l; j++) { console.log(values[j].id); } }
Array for
for (var i=10000; i > 0; i--) { for (var j=0,l=arr.length; j < l; j++) { console.log(arr[j].id); } }
Array forEach
for (var i=10000; i > 0; i--) { arr.forEach(n => console.log(n.id)); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
for-in
Object.keys
Object.values
Array for
Array 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:
for-in vs object.keys vs object.values for objects v2
for-in vs object.keys vs object.values for objects vs arr
for-in vs object.keys vs object.values for objects - output object values
Yet Another Object.keys vs Object.values
Comments
Confirm delete:
Do you really want to delete benchmark?