<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
var person = {name: {first: 'Johnson', last: 'Wang' }, lastName: 'Corcino Alejo'};
_.get(person, 'name.last');
person.name.last
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash | |
native |
Test name | Executions per second |
---|---|
lodash | 3213962.2 Ops/sec |
native | 16465151.0 Ops/sec |
This benchmark compares two ways to retrieve the value 'Wang'
from the person
object:
_.get(person, 'name.last')
): Uses the Lodash library's get()
method, which is designed for safely accessing nested object properties. person.name.last
): Directly accesses the property using dot notation, a standard way to navigate objects in JavaScript.Pros and Cons:
Lodash (_.get
):
Native JavaScript (person.name.last
):
Alternatives:
Other libraries besides Lodash offer similar functionality, such as:
Let me know if you'd like more details about any specific aspect of this benchmark or the libraries mentioned!