Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.keys for-of vs for-in hasOwnProperty
(version: 0)
Original source: https://jsperf.com/object-keys-foreach-vs-for-in-hasownproperty
Comparing performance of:
A vs B
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
// Declaring our Animal object var Animal = function () { this.name = 'unknown'; this.getName = function () { return this.name; } return this; }; // Declaring our Dog object var Dog = function () { // A private variable here var private = 42; // overriding the name this.name = "Bello"; // Implementing ".bark()" this.bark = function () { return 'MEOW'; } return this; }; // Dog extends animal Dog.prototype = new Animal(); // Creating an instance of Dog. var obj = new Dog(); function iterateA() { var ret = ""; for (var prop in obj) { if( obj.hasOwnProperty( prop ) ) { ret += obj[prop]; } } return ret; } function iterateB() { var ret = ""; for (var prop of Object.keys(obj)) { ret += obj[prop]; } return ret; }
Tests:
A
var tmp = iterateA();
B
var tmp = iterateB();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
A
B
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:
undefined vs. typeof vs. in vs. hasOwnProperty vs Object.prototype.hasOwnProperty
undefined vs. typeof vs. in vs. hasOwnProperty.call()
undefined vs. typeof vs. in vs. Object.prototype.hasOwnProperty
hasOwnProperty vs hasOwnProperty .call
in vs Object.hasOwn vs Object.prototype.hasOwnProperty
Comments
Confirm delete:
Do you really want to delete benchmark?