If you are a seasoned JavaScript developer or just getting into it you should definitely checkout and try to incorporate a library called Lo-Dash into your tool box.
In a nutshell, Lo-Dash is a super useful library that gives you access to over 100 extremely performant functions to help you avoid reinventing the wheel whilst writing JavaScript.
To get started with Lo-Dash, all you need to do is load the Lo-Dash library like so:
<script src="lodash.js"></script>
The latest release can be found on the GitHub repository, cdnjs or via NPM.
A Couple Of Basic Lo-Dash Examples
With this simply array of objects we can easily see how handy and powerful Lo-Dash is.
var drinks = [
{ 'name': 'Coke', 'quantity': 2 },
{ 'name': 'Red Bull', 'quantity': 6 }
];
One circumstance that we might come across during development is the need to get all the drink names. By utilising the ._pluck()
function this becomes extremely trivial.
var currentDrinks = _.pluck(drinks, 'name');
console.log(currentDrinks);
// → [‘Coke’, ‘Red Bull’]
Another simple use case is to get the drink with the highest stock level. Here we can use ._max()
like so:
var maxQuantity = _.max(drinks, 'quantity');
console.log(maxQuantity);
// → { 'name': 'Red Bull', 'quantity': 6 }
Live Example
See all the Lo-Dash functions
If you have been into JavaScript development for a while you may of also heard about underscore.js which is very similar to Lo-Dash but has some fundamental differences.
I created Lo-Dash to provide more consistent cross-environment iteration support for arrays, strings, objects, and arguments objects1. It has since become a superset of Underscore, providing more consistent API behavior, more features (like AMD support, deep clone, and deep merge), more thorough documentation and unit tests (tests which run in Node, Ringo, Rhino, Narwhal, PhantomJS, and browsers), better overall performance and optimizations for large arrays/object iteration, and more flexibility with custom builds and template pre-compilation utilities.
— John-David Dalton
Source: Stackoverflow
Hopefully this basic introduction above has you intrigued to get your hands dirty and experience the real power with your own eyes.
Great intro to lo-dash, just got into using it and it provides very powerful functions.
Thanks for the great intro, but are those functions missing in javascript ? is this an add-on library or just a function enhancement ?
Hey @Jacklyn,
These are more like added utilities rather than core function enhancement. Rather then writing these functions yourself for common uses someone has created them and tested them for performance.