Understanding these four ideas will help you predict how any Lodash method behaves before you look it up.
Arrays, array-likes, and collections
Lodash's own category names describe what a method expects:
- Array methods (
chunk,uniq,flatten) expect a true array or an array-like value — anything with a numericlength, includingargumentsobjects and strings. - Collection methods (
map,filter,reduce,groupBy) accept either an array (iterated by index) or a plain object (iterated over its own enumerable string-keyed properties). This is why_.map({ a: 1, b: 2 }, fn)andmap([1, 2], fn)both work. - Object methods (
get,set,merge,keys) operate on plain objects and property paths.
Check a method's own Parameters table in the reference for its exact accepted type — most are explicit about Array, Array|Object, or Object.
Mutating and non-mutating methods
Most Lodash methods return a new array or object and leave their input untouched. A smaller set of methods change their input in place, and Lodash documents this directly in each method's description — look for a Note like "this method mutates array."
var array = [1, 2, 3];
var reversed = _.reverse(array);
reversed === array;
// => true — reverse() mutated `array` and returned the same referencevar array = [5, 6, 7];
var removed = _.remove(array, function (n) { return n > 5; });
array;
// => [5] — remove() mutated the array in place
removed;
// => [6, 7] — and also returns the removed elementsMethods that mutate include fill, pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reverse, and the object methods set, setWith, unset, update, updateWith, merge, mergeWith, assign, assignIn, assignWith, and assignInWith. When you need the original left untouched, either confirm the method returns a copy (most do) or clone first — see Cloning and comparing values.
lodash/fp instead: every method in the functional build returns a new value.Iteratee shorthands
Any parameter documented with a default like [iteratee=_.identity] accepts a function, but also accepts a property-path string, a partial-match object, or a [path, value] pair as shorthand. See Iteratee shorthands and common patterns for the full pattern with examples.
Guarded methods
A subset of methods are written so they're safe to pass directly as the iteratee to every, filter, map, mapValues, reject, and some — Lodash calls out each method's own guard note where it applies (for example, on map and reduce). Native functions with a different second-parameter meaning, such as parseInt, are not guarded — see the footgun example in Iteratee shorthands.
Next steps
- Browse methods by category in the API reference.
- Read Security before using
_.templateor deep-write methods with untrusted input.