Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
IndexOf vs Includes vs lodash includes v3
(version: 0)
Banana
Comparing performance of:
IndexOf vs Includes vs lodash
Created:
4 years ago
by:
Guest
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 = ['banana', 'jesus', 1212312, 2, 4, 'б', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312','sausage', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg', '112312312', 'dsdsdsds', 'sdsdsdsd', 'ergergergerg']
Tests:
IndexOf
array.indexOf('sausage') !== 1
Includes
array.includes('sausage')
lodash
_.includes(array, 'sausage')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
IndexOf
Includes
lodash
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):
Let's break down the provided benchmark and explain what's being tested, compared, and what's at play. **Benchmark Definition** The benchmark is designed to compare three different approaches for checking if an element exists in an array: 1. `array.indexOf('sausage') !== 1` 2. `array.includes('sausage')` 3. `_(_.includes(array, 'sausage'))` (using the Lodash library) **Options being compared** The three options are being compared to see which one is the fastest. * Option 1: Using the `indexOf()` method with a negation. * Option 2: Using the `includes()` method. * Option 3: Using the `_(_.includes(array, 'sausage'))` approach with Lodash. **Pros and Cons** Here's a brief overview of each option: * **Option 1 (indexOf() method)**: + Pros: Simple and widely supported. It returns -1 if the element is not found. + Cons: Returns -1 instead of a boolean value, which can be confusing. Also, it may not be as efficient for large arrays. * **Option 2 (includes() method)**: + Pros: Returns a boolean value indicating whether the element exists in the array. It's more readable and maintainable than Option 1. + Cons: May be slower than Option 3 due to its overhead. * **Option 3 (_(_.includes(array, 'sausage')) using Lodash)**: + Pros: Uses a widely used and well-maintained library (Lodash) for the implementation. It's likely to be fast and efficient. + Cons: Requires an additional dependency (Lodash), which may not be desirable for all users. **Library: Lodash** In this benchmark, Lodash is used to provide the `_(_.includes(array, 'sausage'))` implementation. Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string manipulation, and more. Lodash's `_.includes()` function returns a boolean value indicating whether an element exists in an array. In this case, it's used to check if the string `'sausage'` exists in the provided array. **Special JS feature or syntax** There are no special JavaScript features or syntaxes mentioned in the benchmark definition or test cases. The focus is on comparing three different approaches for checking if an element exists in an array. **Alternatives** If you're looking for alternative approaches, here are a few options: * Using `Array.prototype.some()` and a callback function to check if any element in the array matches the condition. * Using `Array.prototype.every()` and a callback function to check if all elements in the array match the condition.
Related benchmarks:
IndexOf vs Includes vs lodash includes 1231
reduce me test 000009
reduce spread vs reduce
IndexOf vs Includes vs lodash includes on the arrays of strings
Comments
Confirm delete:
Do you really want to delete benchmark?