The power of lodash

by Aymen on 01/5/2016

A JavaScript utility library delivering consistency, modularity, performance, & extras.

 – Source : lodash.com

In production life, it’s a waste of time doing what is already done. In javascript we have a pretty cool  library called “Lodash” it’s tiny and smart, let’s see how :

Example :

Really famous routine, removing an element from simple Javascript Array

Native javascript :

[js]
for (var i = 0; i < tagContainer.length; i++) {
if (tagContainer[i] == removedTag) {
tagContainer.splice(i, 1);
break;
}
};
[/js]

 With lodash : 

[js]
_.pull(tagContainer ,removedTag);
[/js]

How about assigning/getting a value to an element using a string as a name/key?

[js]
var user = {};
_.set(user,’fullname.name’, ‘Aymen’ );
// get name
_.get(user,’fullname.name’);
// Aymen
[/js]

Download : lodash.com

This may be interesting for you

There are 2 comments in this article:

  1. 01/5/2016majdi says:

    yoeman will do that for you 🙂

  2. 01/6/2016aymen says:

    @majdi yoeman is different, it is a scaffolding tool (app or script generator), lodash is a tiny javascript library.

Write a comment: