Lodash Library

After doing project, i still don’t understand why are we using lodash library ? i mean in all of lodash methods we are using normal javascript methods .push(), slice(), findIndex(), so what is the use of lodash ? i am so confused :pensive: :face_with_thermometer:

If i remember correctly, the Codecademy project that you were working on is re-writing some of the lodash.js library. The purpose of the lodash library is that all of the functions you made would be ready to go and save you a lot of time!

Javascript libraries, like lodash, contain a bunch of functions so that you don’t have to re-write bits of commonly used code over and over. The Codecademy lesson asks you to build a bit of the lodash library for good practice! Normally, you wouldn’t have to write the code in a Javascript library, just import it into your Javascript file.

Hope that helps!

2 Likes

Thanks for your reply.
So for example, if i want to use .clamp() method from lodash library in my actual project then i have to just import lodash library, i don’t have to make another method to make clamp() work, right ?

Yeah, exactly!

.clamp() Is already written in the lodash library so once you’ve imported it, you can call the function without writing it yourself.

1 Like

Lodash should contain useful functions/methods to speed up development. You can just use these methods as already mentioned

codecademy also took this opportunity to teach you about how certain of these methods might be implemented

1 Like

Hey @betaslayer45561, when you get a moment I’d appreciate you marking this topic as solved. Thank you!

Edit: looks like @stetim94 got it - thanks stetim!

sorry to rehash the old problems but I was just working through the module and was wondering about something. Why would we use lodash instead of js default methods like whats the benefit of using _.words over of .split() method?

_.words seems to do a better job when dealing with punctuation marks, from the docs:

_.words('fred, barney, & pebbles');
// => ['fred', 'barney', 'pebbles']