<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
cspSrcs = {
key: 'value'
};
_.has(cspSrcs, 'key');
'key' in cspSrcs;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash.has | |
Native JavaScript |
Test name | Executions per second |
---|---|
lodash.has | 7464575.0 Ops/sec |
Native JavaScript | 17482956.0 Ops/sec |
Overview
The provided JSON represents a benchmark test on the MeasureThat.net website, comparing the performance of Lodash's has
function with native JavaScript code for checking if an object has a specific property.
What is tested
Two approaches are compared:
has
function: This function checks if path
is a direct property of object
. The benchmark measures how long it takes to perform this check.in
operator: This approach uses the in
operator to check if an object has a specific property. The benchmark measures how long it takes to perform this check.Options compared
The two options are:
has
functionin
operatorPros and cons of each approach
has
function:in
operator:has
function, and may not handle nested objects as elegantly.Library usage
The benchmark uses the Lodash library, which is a JavaScript utility library that provides a wide range of functions for tasks such as data manipulation, functional programming, and string manipulation. In this specific case, the has
function is used to check if an object has a specific property.
Special JS feature or syntax
There are no special JavaScript features or syntaxes mentioned in the benchmark definition or test cases. The code uses standard JavaScript syntax and does not employ any advanced features such as async/await, Promises, or Web Workers.
Other alternatives
If you need to perform similar checks on objects, other approaches could include:
in
operator (e.g., ${object}['key'] in 'value'
)