๐ŸŒ
Lodash
lodash.com โ€บ docs
Lodash Documentation
Creates an array of values by running each element in collection thru iteratee. The iteratee is invoked with three arguments: (value, index|key, collection). Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues, _.reject, and _.some.
JavaScript library in the functional programming paradigm
Lodash is a JavaScript library which provides utility functions for common programming tasks using the functional programming paradigm. Lodash is a fork of Underscore.js. It joined the Dojo Foundation in 2013, and โ€ฆ Wikipedia
Factsheet
Lodashยฐ
Original author John-David Dalton
Initial release April 23, 2012; 13 years ago (2012-04-23)
Factsheet
Lodashยฐ
Original author John-David Dalton
Initial release April 23, 2012; 13 years ago (2012-04-23)
๐ŸŒ
Lodash
lodash.com
Lodash
Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ lodash-array-complete-reference
Lodash Array Complete Reference - GeeksforGeeks
July 23, 2025 - Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers etc.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ lodash โ€บ lodash_array.htm
Lodash Array Methods
Lodash has many easy to use methods which helps in processing Arrays. This chapter discusses them in detail.
๐ŸŒ
Devhints
devhints.io โ€บ javascript libraries โ€บ lodash cheatsheet
Lodash cheatsheet
_.filter(list, (n) => n % 2) // โ†’ Array _.find(list, (n) => n % 2) // โ†’ item _.findLast(list, ...) // โ†’ item
๐ŸŒ
Dustin John Pfister
dustinpfister.github.io โ€บ 2018 โ€บ 10 โ€บ 02 โ€บ lodash_range
Creating an array of numbers with _.range in lodash | Dustin John Pfister at github pages
October 20, 2021 - This is a post on the _.range method in lodash that can be used to quickly create an array that contains a range of numbers. This is also something that is not that hard to do with plain old vanilla js as well, so I will also be looking at some plain old javaScript solutions for creating number ranges.
Find elsewhere
๐ŸŒ
Envato Tuts+
code.tutsplus.com โ€บ home โ€บ coding fundamentals
Useful Methods for Arrays in the Lodash Library | Envato Tuts+
February 22, 2023 - For example, let's say you are supposed to get weather information from different places stored in an array, and some of the returned values are undefined, false, an empty string, etc. In these cases, you can use the compact() method to filter out all the falsey values, including false, null, undefined, NaN, the empty string "", and 0. Here is an example: There are a variety of methods in Lodash that can help you remove elements from an array.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ lodash โ€บ lodash_quick_guide.htm
Lodash - Quick Guide
Lodash provides various functions for arrays like to iterate and process arrays like first, initial, lastIndexOf, intersection, difference etc.
๐ŸŒ
GitHub
github.com โ€บ lodash โ€บ lodash โ€บ issues โ€บ 953
Ensure something is array ยท Issue #953 ยท lodash/lodash
December 22, 2014 - I think this is a feature request, but it's possible it already exists and I just can't find it. I often find myself writing the following: _.isArray(something) ? something : [something] It would be useful if there were a function called...
Author ย  callumacrae
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ lodash โ€บ difference
The difference() function in Lodash
April 12, 2022 - Here's how JavaScript arrays' `flatMap()` method works, and what you can use it for..
๐ŸŒ
Dustin John Pfister
dustinpfister.github.io โ€บ 2019 โ€บ 02 โ€บ 14 โ€บ lodash_array
lodash array methods collection methods and more | Dustin John Pfister at github pages
November 22, 2021 - That is that an array of javaScript is just a certain kind of object that is formated in a way in which it is a collection of numbered index key and value pairs, along with an array length property that reflects the max size of the array, but not the count of the array as arrays are sparse in javaScript. In addition an array in javaScript has some built in prototype methods that are inherited such as Array.forEach. Many of the lodash array methods are now part of the native javaScript prototype, but that is not the case with all of them.
Top answer
1 of 3
289

The includes (formerly called contains and include) method compares objects by reference (or more precisely, with ===). Because the two object literals of {"b": 2} in your example represent different instances, they are not equal. Notice:

({"b": 2} === {"b": 2})
> false

However, this will work because there is only one instance of {"b": 2}:

var a = {"a": 1}, b = {"b": 2};
_.includes([a, b], b);
> true

On the other hand, the where(deprecated in v4) and find methods compare objects by their properties, so they don't require reference equality. As an alternative to includes, you might want to try some (also aliased as any):

_.some([{"a": 1}, {"b": 2}], {"b": 2})
> true
2 of 3
17

Supplementing the answer by p.s.w.g, here are three other ways for achieving this using lodash 4.17.5, without using _.includes():

Say you want to add an object entry to an array of objects numbers, only if entry does not exist already.

let numbers = [
    { to: 1, from: 2 },
    { to: 3, from: 4 },
    { to: 5, from: 6 },
    { to: 7, from: 8 },
    { to: 1, from: 2 } // intentionally added duplicate
];

let entry = { to: 1, from: 2 };

/* 
 * 1. This will return the *index of the first* element that matches:
 */
_.findIndex(numbers, (o) => { return _.isMatch(o, entry) });
// output: 0


/* 
 * 2. This will return the entry that matches. Even if the entry exists
 *    multiple time, it is only returned once.
 */
_.find(numbers, (o) => { return _.isMatch(o, entry) });
// output: {to: 1, from: 2}


/* 
 * 3. This will return an array of objects containing all the matches.
 *    If an entry exists multiple times, if is returned multiple times.
 */
_.filter(numbers, _.matches(entry));
// output: [{to: 1, from: 2}, {to: 1, from: 2}]

If you want to return a Boolean, in the first case, you can check the index that is being returned:

_.findIndex(numbers, (o) => { return _.isMatch(o, entry) }) > -1;
// output: true
Top answer
1 of 2
44

It's a good idea to look at the more elaborate Underscore.js documentation, from which this distinction is derived. It states:

Collection functions work on arrays, objects, and array-like objects such as arguments, NodeList and similar. But it works by duck-typing, so avoid passing objects with a numeric length property.

Basically, "collections" are things that implement some kind of "iterable" interface, and they internally use the same iteration method (though Lodash source is a bit more convoluted than Underscore). All the "collection methods" do work both on arrays and objects (and a few more iterable things), while the array methods should only be used on arrays (or maybe everything with .length and numeric indices), and the object methods work on any objects.

2 of 2
17

All Arrays are collections but not all collections are arrays. An Object (i.e. {k: v, ... }) is a collection that is not an Array. Many of the iterators can iterate over non-Array collections just fine. In this context you can think of arrays as, more or less, ordered collections that are indexed by consecutive non-negative integers.

For example, both of these work:

_([6, 11, 23]).each(function() {
    console.log(arguments);
});
_({ a: 6, b: 11, c: 23 }).each(function() {
    console.log(arguments);
});

Demo: http://jsfiddle.net/ambiguous/t8a83/

The arguments that the function gets depend on what sort of thing you're iterating over. If you're iterating over an array then you'd get the element and the index, if you're iterating over an Object then you'd get the value and key.

๐ŸŒ
DeepWiki
deepwiki.com โ€บ lodash โ€บ lodash โ€บ 4.1-array-methods
Array Methods | lodash/lodash | DeepWiki
January 11, 2022 - Returns: The slice of array. ... Lodash's array methods are optimized for performance.
๐ŸŒ
DevDocs
devdocs.io โ€บ lodash~3
DevDocs โ€” lodash 3 documentation
lodash 3.10.1 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
๐ŸŒ
DevDocs
devdocs.io โ€บ lodash~2
DevDocs โ€” lodash 2 documentation
lodash 2.4.2 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.