Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.keys vs Object.entries vs Object.values
(version: 0)
Comparing performance of:
Object.keys vs Object.entries vs Object.values
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var someObject = { a: 123, b: 456, c: 789 };
Tests:
Object.keys
var x = Object.keys(someObject);
Object.entries
var x = Object.entries(someObject);
Object.values
var x = Object.values(someObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Object.keys
Object.entries
Object.values
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.keys
80425160.0 Ops/sec
Object.entries
47843772.0 Ops/sec
Object.values
60428832.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** The provided JSON represents a benchmark test case on MeasureThat.net, which compares the performance of three different approaches to iterate over an object's properties: `Object.keys()`, `Object.entries()`, and `Object.values()`. **Options compared:** 1. **Object.keys()**: Returns an array of strings representing the property names of an object. 2. **Object.entries()**: Returns an array of two-element arrays, where each inner array contains a property name and its corresponding value as a string. 3. **Object.values()**: Returns an array containing the values of an object. **Pros and Cons:** 1. **Object.keys()**: * Pros: Simple to use and understand, easy to iterate over properties by their names. * Cons: Returns property names only, not the corresponding values or arrays. Iterating over the result requires additional parsing. 2. **Object.entries()**: * Pros: Returns both property names and values as an array of two-element arrays, making it easier to access and manipulate both. * Cons: Returns a more complex data structure than `Object.keys()`, which can be slower for iteration due to the added overhead. 3. **Object.values()**: * Pros: Returns only the object's values, which can be useful in certain scenarios. * Cons: Does not provide access to property names, requiring additional parsing or lookup. **Library and its purpose** None of the benchmarked functions use a specific library. They are built-in JavaScript methods for working with objects. **Special JS feature or syntax** None mentioned. The benchmark only tests standard JavaScript features and syntax. **Other alternatives** While not explicitly listed in the benchmark, other ways to iterate over an object's properties include: 1. Using `for...in` loop: Iterates over property names using a loop. 2. Using `Object.keys()` with a callback function: Allows iterating over property values while still accessing their names. However, these alternatives are not compared in this specific benchmark. **Benchmark preparation code** The provided JavaScript script creates an object named `someObject` and assigns it to the variables used in each benchmarked method: ```javascript var someObject = { a: 123, b: 456, c: 789 }; ``` This object serves as the test data for the comparison.
Related benchmarks:
Object.keys vs Object.values
Object.keys vs Object.getOwnPropertyNames - objects with 0 keys
key in object vs object.key
entries vs keys lookup
Comments
Confirm delete:
Do you really want to delete benchmark?