Questions tagged [lodash]

A modern JavaScript utility library delivering modularity, performance, and extras.

Lodash is a JavaScript utility library delivering consistency, customization, performance, and extra features. It includes an Underscore.js build that can be used as a replacement for , and indeed its functionality is a superset of Underscore.js's.

It comes in a "modern" build for newer browsers, a compatibility build for older browsers and , and per-method builds (individual features).

Lodash’s modular methods are great for:

  • Iterating arrays, objects, & strings
  • Manipulating and testing values
  • Creating composite functions
  • Creating your own mixin for Lodash

Useful links:

6953 questions
1715
votes
12 answers

Differences between Lodash and Underscore.js

Why would someone prefer either the Lodash or Underscore.js utility library over the other? Lodash seems to be a drop-in replacement for underscore, the latter having been around longer. I think both are brilliant, but I do not know enough about how…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
522
votes
5 answers

Lodash - difference between .extend() / .assign() and .merge()

In the Lodash library, can someone provide a better explanation of merge and extend / assign. Its a simple question but the answer evades me nonetheless.
JDillon522
  • 19,046
  • 15
  • 47
  • 81
486
votes
25 answers

How to do a deep comparison between 2 objects with lodash?

I have 2 nested objects which are different and I need to know if they have a difference in one of their nested properties. var a = {}; var b = {}; a.prop1 = 2; a.prop2 = { prop3: 2 }; b.prop1 = 2; b.prop2 = { prop3: 3 }; The object could be much…
JLavoie
  • 16,678
  • 8
  • 33
  • 39
419
votes
33 answers

Can't perform a React state update on an unmounted component

Problem I am writing an application in React and was unable to avoid a super common pitfall, which is calling setState(...) after componentWillUnmount(...). I looked very carefully at my code and tried to put some guarding clauses in place, but the…
Igor Soloydenko
  • 11,067
  • 11
  • 47
  • 90
366
votes
8 answers

Lodash remove duplicates from array

This is my data: [ { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello-how-are-you', id: "23" }, …
ChrisRich
  • 8,300
  • 11
  • 48
  • 67
325
votes
6 answers

What happened to Lodash _.pluck?

I once used Lodash _.pluck...I loved pluck... Realizing Lodash no longer supports pluck (as of Lodash 4.x), I'm struggling to remember what to use instead... I went to the docs, hit cmd-f, typed 'pluck', but my poor abandoned friend is not even…
sfletche
  • 47,248
  • 30
  • 103
  • 119
298
votes
23 answers

Importing lodash into angular2 + typescript application

I am having a hard time trying to get the lodash modules imported. I've setup my project using npm+gulp, and keep hitting the same wall. I've tried the regular lodash, but also lodash-es. The lodash npm package: (has an index.js file in the package…
Davy
  • 6,295
  • 5
  • 27
  • 38
277
votes
12 answers

How can I find and update values in an array of objects?

I have an array of objects. I want to find by some field, and then to change it: var item = {...} var items = [{id:2}, {id:2}, {id:2}]; var foundItem = items.find(x => x.id == item.id); foundItem = item; I want it to change the original object.…
user3712353
  • 3,931
  • 4
  • 19
  • 33
268
votes
10 answers

Correct way to import lodash

I had a pull request feedback below, just wondering which way is the correct way to import lodash? You'd better do import has from 'lodash/has'.. For the earlier version of lodash (v3) which by itself is pretty heavy, we should only import a…
Bill
  • 17,872
  • 19
  • 83
  • 131
245
votes
27 answers

How to remove undefined and null values from an object using lodash?

I have a Javascript object like: var my_object = { a:undefined, b:2, c:4, d:undefined }; How to remove all the undefined properties? False attributes should stay.
JLavoie
  • 16,678
  • 8
  • 33
  • 39
235
votes
8 answers

How to filter keys of an object with lodash?

I have an object with some keys, and I want to only keep some of the keys with their value? I tried with filter: const data = { aaa: 111, abb: 222, bbb: 333 }; const result = _.filter(data, (value, key) =>…
Freewind
  • 193,756
  • 157
  • 432
  • 708
218
votes
29 answers

Error: EACCES: permission denied

I run npm install lodash but it throws Error: EACCES: permission denied error. I know it is permission issue but as far as I know, sudo permission is not required for installing node module locally. If I run it with sudo, it gets installed inside…
xruptronics
  • 2,785
  • 3
  • 12
  • 17
209
votes
8 answers

LoDash: Get an array of values from an array of object properties

I'm sure it's somewhere inside the LoDash docs, but I can't seem to find the right combination. var users = [{ id: 12, name: 'Adam' },{ id: 14, name: 'Bob' },{ id: 16, name: 'Charlie' },{ id: 18, …
YarGnawh
  • 4,574
  • 6
  • 26
  • 37
207
votes
12 answers

transform object to array with lodash

How can I transform a big object to array with lodash? var obj = { 22: {name:"John", id:22, friends:[5,31,55], works:{books:[], films:[],} 12: {name:"Ivan", id:12, friends:[2,44,12], works:{books:[], films:[],} } // transform to var arr =…
siavolt
  • 6,869
  • 5
  • 24
  • 27
204
votes
11 answers

How to Import a Single Lodash Function?

Using webpack, I'm trying to import isEqual since lodash seems to be importing everything. I've tried doing the following with no success: import { isEqual } from 'lodash' import isEqual from 'lodash/lang' import isEqual from…
cvdv
  • 2,691
  • 3
  • 14
  • 29
1
2 3
99 100