Speed up your coding process using Lodash, save time writing the same old functions

What is Lodash?

Lodash is a JavaScript library that provides utility functions for common programming tasks. It uses a functional programming paradigm. Lodash was inspired by Underscore.js,Lodash is also updated more frequently than Underscore.

The Lodash documentation can be found at https://lodash.com/. It has dozens of useful functions for working with arrays, objects, strings, and many others.

Why would use it for?

Lodash helps to deal with all types of objects as it saves a lot of time coding common functions. It makes the code look better in just a few lines as it works pretty much in all browsers, even IE6.

How to use Lodash?

// Let’s install Lodash first:

$ npm install lodash

// How to use it with React:

import _ from 'lodash';

// To import specific methods that we’ll use later we should call them inside of curly brackets:

import { sum, chunk, compact, flattenDeep } from 'lodash';

Let’s dive in with some examples:

_.sum

We can also do the same to objects:

_.chunk

__.chunk returns the new array of chunks:

_.compact

_.compact returns the new array of chunks:

_.concat

_.concat returns the new concatenated array:

_.flattenDeep

_.flattenDeep returns the new flattened array.

_.head

_.head returns the first element of array.

_.tail

_.tail returns the slice of array.

_.join

_.join returns the joined string:

_.merge

_.merge returns an object with the same key:

Final thought

Lodash has a lot of helper functions to save time. The library itself is super light ~72.5 KB, I would personally recommend it for fast performance.

If you’re still shaky on your feet, please check out their documentation.

Be confident and write some code of your own, build Something since there is no substitute for getting your hands dirty.

Software engineer | Full Stack Developer | Programmer | Designer & Entrepreneur

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store