Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.indexOf vs Array.includes vs lodash includes with numerical values
(version: 0)
Comparing performance of:
Array.indexOf vs Array.includes vs lodash includes
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var array = [1, 10, 5, 6, 2, 4, 3, 8, 7, 9]
Tests:
Array.indexOf
array.indexOf(3) !== -1
Array.includes
array.includes(3)
lodash includes
_.includes(array, 3)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.indexOf
Array.includes
lodash includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.indexOf
71106160.0 Ops/sec
Array.includes
47325512.0 Ops/sec
lodash includes
21562526.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that tests the performance of three different methods to check if an element exists in an array: 1. `Array.indexOf()` 2. `Array.includes()` 3. `_includes()` from the Lodash library These methods are compared to determine which one is the fastest. **Options being compared** There are two main options being compared: built-in JavaScript methods (`Array.indexOf()` and `Array.includes()`) vs a third-party library method (`_.includes()` from Lodash). **Pros and cons of each approach** * **Built-in JavaScript methods (`Array.indexOf()` and `Array.includes()`)`** + Pros: - Widely supported by most browsers - Simple and concise syntax + Cons: - Can be slower due to the overhead of method calls - May not be optimized for performance * **Third-party library method (`_.includes()` from Lodash)`** + Pros: - Optimized for performance, often written in native code - Can provide additional features and functionality + Cons: - Requires an external dependency (the Lodash library) - May not be supported by all browsers **Library and its purpose** In this benchmark, the Lodash library is used to provide a third-party implementation of the `_.includes()` method. The library's purpose is to provide a more efficient and flexible alternative to the built-in JavaScript methods. **Special JS feature or syntax** There doesn't appear to be any special JS features or syntax being tested in this benchmark. The code is straightforward and uses standard JavaScript constructs. **Other alternatives** If you wanted to implement your own custom implementation of the `includes()` method, you could use a simple loop to iterate through the array elements and check for the target value. However, this approach would likely be slower than using an optimized library like Lodash or relying on built-in JavaScript methods. In summary, the benchmark tests the performance of three different methods to check if an element exists in an array: built-in JavaScript methods (`Array.indexOf()` and `Array.includes()`), a third-party library method (`_.includes()` from Lodash), and custom implementation (although not explicitly tested).
Related benchmarks:
IndexOf vs Includes array of numbers
IndexOf vs Includes vs _.includes for number array
array IndexOf vs array Includes vs lodash indexOf
array using indexOf vs includes vs some
Comments
Confirm delete:
Do you really want to delete benchmark?