Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
$.inArray vs Array.prototype.includes
(version: 0)
Comparing performance of:
$.inArray vs Array.prototype.includes
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js'></script>
Tests:
$.inArray
$.inArray("House", ["Apartment", "School", "House"]);
Array.prototype.includes
["Apartment", "School", "House"].includes("House");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
$.inArray
Array.prototype.includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
$.inArray
13669000.0 Ops/sec
Array.prototype.includes
123401664.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and some pros/cons of each approach. **Benchmark Definition** The benchmark compares two methods for searching an array: `$inArray` (part of jQuery) and `Array.prototype.includes`. The test cases are designed to demonstrate which method is faster. **Options Compared** There are only two options being compared: 1. `$inArray`: A part of the jQuery library, specifically designed for finding elements in an array by value. 2. `Array.prototype.includes`: A built-in JavaScript method that checks if a specific value exists in an array. **Pros and Cons** Here's a brief summary of each option: * `$inArray`: + Pros: Easy to use, especially when working with jQuery-specific data structures. Fast performance for simple searches. + Cons: Not part of the built-in JavaScript API, relies on jQuery being loaded. May be slower than native `includes()` for very large arrays or complex searches. * `Array.prototype.includes`: + Pros: Part of the standard JavaScript API, making it widely supported and fast for most use cases. Can handle large arrays and complex searches efficiently. + Cons: May not be as intuitive for developers without a strong background in JavaScript. **Library and Purpose** The jQuery library is a popular, feature-rich framework that simplifies DOM manipulation and event handling. `$inArray` is one of its utility methods, designed to make common array operations easier to perform. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes being used in this benchmark, so I won't comment on them. **Other Alternatives** For searching arrays, other built-in JavaScript methods you might consider using (in addition to `Array.prototype.includes`) include: * `indexOf()`: Similar to `includes()`, but returns the index of the first occurrence instead of a boolean value. * `some()` and `every()`: Methods that check if at least one or all elements in an array meet a condition, respectively. Keep in mind that these alternatives might have slightly different performance characteristics depending on your specific use case. **Benchmark Preparation Code** The provided script preparation code includes the jQuery library, which is necessary for using `$inArray`. The HTML preparation code adds a reference to this library.
Related benchmarks:
Lodash.js vs instanceof Array
JavaScript Benchmark: includes vs indexOf
Array.prototype.includes vs underscore.includes
JS array emptiness check
Comments
Confirm delete:
Do you really want to delete benchmark?