DEV Community

Discussion on: 5 Must Know Lodash Methods

Collapse
 
camskithedev profile image
Cameron Lucas • Edited

You are not wrong! Lodash has a bunch of methods that just make doing certain tasks easier. Adding Lodash to your Javascript project adds these methods some other frameworks like Django or Ruby on Rails would have out of the box. Such as the zip method in Ruby on Rails which will zip together two arrays into one. Javascript doesn't have this functionality out of the box... Lodash has a _.zip method. Don't get me wrong you could also do this with the array .map method in Javascript. As for the library overhead you could always import each method individually.

Ex. const zip = require("lodash/zip");

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Probably would have been better to show examples of where using Lodash would actually have some benefit

Thread Thread
 
camskithedev profile image
Cameron Lucas

Maybe in my next post! 😉 say tuned lol!

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

'Tuned'

Thread Thread
 
murkrage profile image
Mike Ekkel

I see what you did there 👀

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

You certainly should only import the modules you use, otherwise a few convenience methods are taking up more space than whole frameworks like React. Functions such as debounce() in lodash have tons of options that make them much heavier than lightweight implementations (which are mostly what it is used for) - if you aren't using the options for trailing and leading edges, it's costing "something".

For me in big apps that are likely to use lots of utility methods over time, I'd take Sugar.js because that has some really useful functions - like Date.create("Next monday at 2pm"), debounce etc. It's also 1/3 the size of lodash if you include it all (and you don't have to).

sugar

Collapse
 
bukazoltan profile image
bukazoltan

I don't know anything about ruby on rails but isn't that concat? w3schools.com/jsref/jsref_concat_a...

Thread Thread
 
camskithedev profile image
Cameron Lucas

It's a little different concat would join the two arrays. So if you had [1, 3, 5] and [2, 4]. The results of concatenation would be [1, 3, 5, 2, 4]. The zip method would zip the two arrays together like a zipper. The results would look like this [1, 2, 3, 4, 5]

Thread Thread
 
bukazoltan profile image
bukazoltan

So basically concat + sort?