Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object.values(obj) vs for...in
(version: 0)
Object.values(obj) function vs using a for...in loop.
Comparing performance of:
Object.values(obj) vs for...in
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function extractValues(obj) { const result = []; for(var key in obj) { result.push(obj[key]); } return result; }
Tests:
Object.values(obj)
var a = { a: 1, b: 2, c: 3}; Object.values(a);
for...in
var a = { a: 1, b: 2, c: 3}; extractValues(a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.values(obj)
for...in
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!
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down the benchmark test case. **What is being tested?** The test case compares two ways of extracting values from an object: 1. Using the `Object.values()` function 2. Using a traditional `for...in` loop with `result.push(obj[key])` **What options are compared?** Two options are compared: * `Object.values(a);`: This uses the modern JavaScript feature `Object.values()` to extract the values from an object. * `extractValues(a);`: This uses a traditional `for...in` loop and manual iteration to extract the values. **Pros and Cons:** Here's a brief summary of the pros and cons of each approach: 1. **Object.values()**: This method is concise, easy to read, and efficient. It returns an array of values extracted from the object. * Pros: + Concise code + Easy to understand + Efficient execution * Cons: + Requires modern JavaScript support (ES6+) 2. **for...in loop**: This traditional approach uses a manual loop to iterate over the object's keys and extract values. * Pros: + Works in older browsers that don't support `Object.values()` + Can be useful for educational purposes or specific use cases * Cons: + Less concise code + May have performance issues due to loop overhead **Library used:** No external library is used in this test case. **Special JavaScript feature or syntax:** The `Object.values()` function is a modern JavaScript feature introduced in ECMAScript 2015 (ES6). It returns an array of values extracted from the object, ignoring property names. If you're not familiar with `Object.values()`, it's similar to using `Object.keys()` but instead returns an array of values instead of keys.
Related benchmarks:
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object
Performance of Object.values(obj) vs_.values() vs for-in to extract values from an object
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object with 1000 entries-2
Performance of Object.values(obj) vs_.values() vs for...in to extract values from an object with 1000 entries-3
Comments
Confirm delete:
Do you really want to delete benchmark?