Lodash _.spread() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.spread unpacks array-like arguments into discrete parameters.
  • How the optional start index mixes fixed prefixes with spread tails.
  • Async tuple patterns with Promise.prototype.then.
  • Pitfalls when arity, holes, or non-array inputs slip through.

Prerequisites

Read _.rest(), _.partial(), and the Function hub.

  • Function.prototype.apply: supplying an arguments array.
  • Promises: resolving to structured tuples.

Overview

_.spread(func, [start]) adapts functions expecting discrete parameters so callers can pass array-like bundles—ideal after operations that naturally produce tuples.

Syntax

javascript
_.spread(func, [start])
  • func: callee receiving expanded arguments.
  • start: index of the argument to spread (defaults to 0).
  • returns: wrapped invoker performing the expansion.
1

Spread a single tuple argument

Default start is 0, so the wrapper expects one array-like holding every positional.

javascript
import spread from "lodash/spread";

const describe = spread(function (subject, verb, obj) {
  return subject + " " + verb + " " + obj + ".";
});

describe(["Ada", "wrote", "notes"]);
// "Ada wrote notes."
2

Pipe tuples through Promises

.then forwards one resolved value—when that value is an array, spread feeds each slot into your merger.

javascript
import spread from "lodash/spread";

const combine = spread(function (width, height) {
  return width * height;
});

Promise.resolve([8, 6]).then(combine).then(console.log);
// logs 48
3

Keep a prefix argument before spreading

Set start = 1 so the zeroth argument stays scalar while the next slot expands.

javascript
import spread from "lodash/spread";

const greetParts = spread(function (name, sep, word) {
  return name + sep + word;
}, 1);

greetParts("Ada", [" says ", "hello"]);
// "Ada says hello"

📋 _.spread vs _.rest vs apply

ToolShape changeTypical source
_.spreadArray-like argument → discrete paramsTuples from APIs or Promises
_.restMany invocation args → trailing arrayVariadic CLI-style inputs
Function.applyManual one-off expansionLow-level control without lodash wrappers

Pitfalls to avoid

Arity

Tuple length mismatches

Sparse arrays or shorter tuples yield undefined parameters—validate lengths before spreading user data.

Objects

Non-array iterables

Lodash relies on array-like length indexing; arbitrary objects without numeric indices fail silently.

Composition

Double spreading

Combining spread with rest without a diagram invites confusion—keep intermediate shapes documented.

❓ FAQ

A wrapper that invokes func after expanding the argument found at start into individual positional parameters—default start is 0 so the first argument must be array-like.
rest collapses trailing invocation arguments into one array parameter; spread takes an array-like argument and fans it out across parameters—they are complementary transforms.
Conceptually similar for the spread segment, but spread returns a reusable wrapper with optional start offsets and lodash metadata.
Yes—Promise.resolve([a,b]).then(_.spread(fn)) is a common pattern when async work yields tuple arrays.
Use import spread from "lodash/spread" for tree-shaking friendly bundles.

Summary

Did you know?

Under the hood lodash treats the value at the spread index as apply-style input—flattening one array slot into consecutive parameters—so pairing spread with Promise.all tuples feels natural.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful