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:

6219 questions
1657
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
  • 71,376
  • 65
  • 208
  • 328
498
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
  • 16,942
  • 15
  • 41
  • 73
374
votes
23 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
  • 13,438
  • 7
  • 29
  • 35
299
votes
5 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
  • 36,606
  • 25
  • 86
  • 108
280
votes
7 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
  • 6,698
  • 9
  • 37
  • 56
279
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
  • 5,760
  • 4
  • 21
  • 31
243
votes
25 answers

How to group an array of objects by key

Does anyone know of a (lodash if possible too) way to group an array of objects by an object key then create a new array of objects based on the grouping? For example, I have an array of car objects: var cars = [ { 'make': 'audi', …
Trung Tran
  • 9,709
  • 34
  • 97
  • 171
210
votes
6 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
  • 13,703
  • 14
  • 67
  • 112
206
votes
6 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
  • 177,284
  • 143
  • 381
  • 649
201
votes
21 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
  • 7,161
  • 7
  • 39
  • 73
199
votes
24 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
  • 13,438
  • 7
  • 29
  • 35
179
votes
11 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
  • 5,721
  • 4
  • 19
  • 26
178
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
  • 3,970
  • 6
  • 20
  • 35
178
votes
9 answers

How can I remove an element from a list, with lodash?

I have an object that looks like this: var obj = { "objectiveDetailId": 285, "objectiveId": 29, "number": 1, "text": "x", "subTopics": [{ "subTopicId": 1, "number": 1 }, { "subTopicId": 2, …
Samantha J T Star
  • 26,790
  • 72
  • 224
  • 390
176
votes
8 answers

Javascript ES6/ES5 find in array and change

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
  • 2,741
  • 4
  • 13
  • 31
1
2 3
99 100