lodash array methods collection methods and more
1 - lodash array methods
So in this section I will be going just over some array methods in lodash, and briefly cover some of the collection methods as well later in this post.
1.1 - The _.chunk lodash array method
The _.chunk method is a lodash array method that can be used to break a linear array into an array of arrays of a given length. The need to do this comes up now and then and the chunk method helps to make quick work of this, and allow me to move on with a project rather than writing this usual suspect from scratch.
1.2 - The _.compact lodash array method
The compact method as well as the lodash filter, and native array filter methods will all return a new array rather than mutating an array in place.
1.3 - The _.flatten method
1.4 - The _.zip method
The zip method takes two or more arrays and zips theme together into a single array. I can not say that I find myself using this one that often in actual projects, but it is an example of an array method that does not show up in the array prototype.
2 - lodash collections methods that also work with arrays, and also collection objects in general
2.1 - Lodash find
The lodash fine collection method can be used to find a single value in an array of values. It can also be used to find an Object in an array of objects also. The lodash find method is useful for fining a single value in an array, but it is not the same thing as sorting, filtering, reducing, or mapping. In some cases I might want to find the top five of something for example, so for that I would want to sort and slice.
2.2 - lodash map method can be used map values to an array
The lodash map method is another method in lodash where the native counterpart Array.map only works with arrays. The lodash map method can map values to an array or any collection object with the value that is returned by the function that it is given.
2.3 - Lodash filter
3 - Conclusion
If you enjoyed this post you might want to check out my main post on lodash in general.