lodash js code example

Example 1: import lodash

// import entire library
import _ from "lodash"
const nums = [1, 2, 2, 3, 1, 4]
let res = _.uniq(nums)

// import methods by name
// Still loads entire lodash library!!
import { uniq } from "lodash"
const nums = [1, 2, 2, 3, 1, 4]
let res = uniq(nums) // better readability

// import only what you need
import uniq from "loadash/uniq"
const nums = [1, 2, 2, 3, 1, 4]
let res = uniq(nums)

Example 2: lodash npm

$ npm i -g npm
-----------------------
$ npm i --save lodash

Example 3: lodash

$ npm i -g npm$ npm i --save lodash

Example 4: Lodash

_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });// → { 'a': 1, 'b': 2 }_.partition([1, 2, 3, 4], n => n % 2);// → [[1, 3], [2, 4]]