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
67
votes
4 answers

How to make lodash work with Angular JS?

I'm trying to use lodash use it at ng-repeat directives, in this way:
Hello {{n}}
Being GridController: IndexModule.controller('GridController', function ()…
diegoaguilar
  • 8,179
  • 14
  • 80
  • 129
66
votes
8 answers

Sort array of objects with date field by date

Given the following array of objects, I need to ascending sort them by the date field. var myArray = [ { name: "Joe Blow", date: "Mon Oct 31 2016 00:00:00 GMT-0700 (PDT)" }, { name: "Sam Snead", date: "Sun Oct 30 2016 00:00:00…
wonder95
  • 3,825
  • 8
  • 45
  • 74
66
votes
3 answers

lodash _.find all matches

I have simple function to return me object which meets my criteria. Code looks like: var res = _.find($state.get(), function(i) { var match = i.name.match(re); return match && (!i.restrict ||…
Andurit
  • 5,612
  • 14
  • 69
  • 121
62
votes
7 answers

Merge Array of Objects by Property using Lodash

I have two arrays of objects that represent email addresses that have a label and a value: var original = [ { label: 'private', value: 'private@johndoe.com' }, { label: 'work', value: 'work@johndoe.com' } ]; var update = [ …
benjiman
  • 3,888
  • 4
  • 29
  • 44
62
votes
1 answer

Lodash .clone and .cloneDeep behaviors

I try to clone an array of objects with nested objects. Something like: var data = [ { id: 1, values: { a: 'a', b: 'b' } }, { id: 2, values: { c: 'c', d: 'd' } } ]; _.Clone With the _.clone method and the isDeep parameter at true: var clone…
GG.
  • 21,083
  • 14
  • 84
  • 130
62
votes
8 answers

lodash Filter collection using array of values

I would like to filter a collection using array of property value. Given an array of IDs, return objects with matching IDs. Is there any shortcut method using lodash/underscore? var collections = [{ id: 1, name: 'xyz' }, { id: 2, …
Amitava
  • 5,013
  • 9
  • 37
  • 50
59
votes
2 answers

What's the difference between transform and reduce in lodash

Other than stating "transform is a more powerful alternative to reduce", I can find no documentation of what the differences are. What are the differences between transform and reduce in lodash (Other than it being 25% slower)?
Kris Erickson
  • 33,454
  • 26
  • 120
  • 175
58
votes
2 answers

Sort array with lodash by value (integer)

I'm really struggling on that but I cannot find a solution. I have an array and I want to sort it by value (all integers). I thought, well let's use lodash, there sure must be a handy function for that. Somehow I cannot figure out to do this…
Merc
  • 4,241
  • 8
  • 52
  • 81
57
votes
10 answers

Filter array of objects whose any properties contains a value

I'm wondering what is the cleanest way, better way to filter an array of objects depending on a string keyword. The search has to be made in any properties of the object. When I type lea I want to go trough all the objects and all their properties…
Léo Coco
  • 4,022
  • 11
  • 52
  • 97
56
votes
3 answers

How to stop lodash.js _.each loop?

I have this rows code: _.each($scope.inspectionReviews, function (value, key) { alert("status=" + value.IsNormal + " " + "name=" + value.InspectionItemName); if (!value.IsNormal) { $scope.status = false; return; } …
Michael
  • 13,950
  • 57
  • 145
  • 288
54
votes
2 answers

Difference between _.forEach and _.forOwn in lodash

What is the difference between these two methods when iterating over an object?
Novellizator
  • 13,633
  • 9
  • 43
  • 65
54
votes
4 answers

Can I debounce or throttle a watched in AngularJS using _lodash?

I have the following which does a watch on an field that's bound to $scope.id. Every time the input field value changes the watch function gets executed: $scope.$watch("id", function (id) { // code that does something based on…
user1943020
51
votes
6 answers

Exclude some properties in comparison using isEqual() of lodash

I am using _.isEqual that compares 2 array of objects (ex:10 properties each object), and it is working fine. Now there are 2 properties (creation and deletion) that i need not to be a part of comparison. Example: var obj1 = {name: "James", age:…
Marco Santos
  • 915
  • 2
  • 11
  • 24
50
votes
6 answers

underscore/lodash unique by multiple properties

I have an array of objects with duplicates and I'm trying to get a unique listing, where uniqueness is defined by a subset of the properties of the object. For example, {a:"1",b:"1",c:"2"} And I want to ignore c in the uniqueness comparison. I can…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
49
votes
8 answers

equivalent of _.pick() but for array in Lo-dash

I have the following collection: var columns = [ { key:'url', width:20, type:'text' }, { key:'title', width:21, type:'text' }, { key:'desc', width:22, type:'text' }, { key:'domain', width:23, type:'text' }, { key:'user',…
pery mimon
  • 7,713
  • 6
  • 52
  • 57