15 Useful Lodash Methods for Everyday Coding (Part-1)
Lodash is one of the most popular open-source JavaScript libraries. It implements a lot of functional programming helpers that make everyday coding easier. It’s something I use often in my own development work, and so I wanted to share with you some of the methods that I find myself using a lot.
In this short post, we’ll go over 15 everyday methods that, when used properly, can speed up development and make your code more readable.
1. shuffle
Creates an array of shuffled values (using a version of the Fisher-Yates shuffle).
2. orderBy
Creates an array of elements, sorted in the specified order by the results of running each element in a collection thru each iteratee.
3. chunk
Creates an array of elements split into groups of a specified size (if the array can’t be split evenly, the final chunk will only contain the remaining elements).
4. take
Creates a slice of the array with n elements taken from the beginning.
5. difference
Creates an array of the values not included in the other given arrays. The order and references of result values are determined by the first array.
6. intersection
Creates an array of unique values that are included in all given arrays. The order and references of result values are determined by the first array.
7. isEmpty
Checks if the value is an empty object, collection, map, or set (objects are considered empty if they have no own enumerable string keyed properties
That’s it!
Here you can check out the code, you will find the lifecycle.