What is a Lodash Library?
It is used for simplifying the handling and edition of objects, arrangements, etc. since this provides many useful methods to do so. At the same time, simplifying this work achieving that our code be much legible and easy to follow for third parties.
As we said previously, Lodash is the most famous successor of underscore.js. At first it was a simple “fork” and more features were added.
To this day it has been completely redesigned.
You have the information in GitHub over here.
You have all the documentation over here.
Installation of Lodash
- Web Navigator
npm install --save lodash
- Use in NodeJS (In our Node file, we charge the component)
const _ = require('lodash')
Traditional way vs Lodash
Then, we are going to take a look of some examples about how certain functions are executed with Lodash.
- Return the value of a key of the first item of an array that is the value of another key:
- Get random number between two numbers:
- Extend object:
- Get last element:
Lodash is, without a doubt, an extremely useful library. I would continue to use it in all of my NodeJS project.
The advantages that stand out the most is the reduced number of repetitive codes and the improved quality of application logic.
However, what has helped me the most has been the ability to think in a more functional way. I shred my application into smaller modules with a singular focus and no side effects.
This modularity also allows me to write a higher quality code.