Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object array find vs _.find
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.find
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
Tests:
array find
var a = [{ name: "joe", age: 12 }, { name: "alf", age: 11 }]; var b = a.find(item => item.age === 11);
_.find
var a = [{ name: "joe", age: 12 }, { name: "alf", age: 11 }]; var b = _.find(a, item => item.age === 11);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array find
_.find
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.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark measures the performance difference between two approaches to find an element in an array: using the new ES6 spread operator (`Object.values()` or `...`) and the traditional `concat()` method. **Options Compared** Two options are compared: 1. **ES6 Spread Operator (Object.values() or ...)** * This approach uses the spread operator to create a copy of the original array, allowing for faster iteration. * Pros: + Cleaner and more concise code + Can be used with other array methods like `map()` and `reduce()` * Cons: + May not work as expected in older browsers or environments that don't support modern JavaScript features 2. **Traditional Concat() Method** * This approach creates a new array by concatenating the original array to an empty array. * Pros: + Widely supported across different browsers and environments * Cons: + Can be slower due to the extra function call and array creation **Library Used** The benchmark uses Lodash, a popular JavaScript utility library, in one of the test cases. Specifically, it uses `_.find()` to find an element in the array. Lodash is often used for its concise and expressive API, but it also adds some overhead due to the need to import and bundle the library. In this case, the benchmark is testing a specific method (`_.find()`) from Lodash against the native JavaScript approach. **Special JS Feature/Syntax** The test cases use a modern JavaScript feature: **arrow functions** (`item => item.age === 11`). Arrow functions were introduced in ECMAScript 2015 (ES6) and provide a concise way to define small, single-expression functions. They are widely supported across modern browsers and environments. **Other Alternatives** If you wanted to implement the `concat()` method or use another approach to find an element in an array, here are some alternatives: * Using `Array.prototype.indexOf()` or `Array.prototype.findIndex()`: These methods are built into the JavaScript Array prototype and can be used to find the index of a specific element. * Using a library like **Underscore.js** (which is similar to Lodash): This library provides a comprehensive set of utility functions, including `find()`. * Implementing your own loop-based solution: You could write a simple loop to iterate over the array and check each element until finding a match. However, for this specific benchmark, using the ES6 spread operator or traditional `concat()` method is the focus, as they provide different trade-offs in terms of performance, code readability, and browser support.
Related benchmarks:
native find vs lodash _.find..
array find vs _.find vs _.find (Array) vs _.find (Object)
array find vs some vs lodash
native find vs lodash _.find_fork
Compare prototype.find vs lodash/find
Comments
Confirm delete:
Do you really want to delete benchmark?