Lodash _.shuffle() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Creates an array of shuffled values using a version of the Fisher–Yates shuffle. Returns a new array — the source is never reordered in place. Part of Lodash 4.x Collection (since 0.1.0).

Pass the required arguments shown below. Lodash Collection helpers usually return a new value — check whether the source is mutated.

Syntax

Call _.shuffle on a collection. Start with this line.

Lodash
_.shuffle(collection)
CallWhat it does
_.shuffle(collection)Primary signature.
_.shuffle(collection)Call with a collection argument.

Prefer import shuffle from "lodash/shuffle" when you want a smaller bundle.

Library declarations
Lodash
_.shuffle(collection)

Parameters

ParameterDescription
collectionRequired. Array or object to shuffle

Return Value

Return ValueDescription
*New array in random order

Lodash Examples

Example 1 — Official: Shuffle an Array

Permute four numbers into a new order.

Lodash
_.shuffle([1, 2, 3, 4]);
// → [4, 1, 3, 2]   (docs example; your order may differ)
Try It Yourself

How It Works

  1. Copy. Lodash works on a new array of the values.
  2. Swap. Fisher–Yates randomly swaps from the end toward the start.
  3. Result. Every permutation is equally likely.
  4. Length. Same length as the source — nothing dropped.

Example 2 — Shuffle a List of Names

Useful for random seating, quiz order, or playlist demos.

Lodash
_.shuffle(["Ada", "Lin", "Sam", "Joy"]);
// → ["Sam", "Ada", "Joy", "Lin"]   (example)
Try It Yourself

How It Works

  1. Source. Four string elements.
  2. Permute. All four appear exactly once in the result.
  3. New array. Safe to bind in React/Vue state without mutating props.
  4. Repeat. Call again for a fresh order.

Example 3 — Source Stays Unchanged

Prove the original array is not reordered in place.

Lodash
var nums = [1, 2, 3, 4];
var mixed = _.shuffle(nums);

// mixed → e.g. [3, 1, 4, 2]
// nums  → [1, 2, 3, 4]  (still original order)
Try It Yourself

How It Works

  1. Assign. Keep a reference to the original array.
  2. Shuffle. Lodash returns a different array instance.
  3. Compare. nums still reads [1, 2, 3, 4].
  4. Objects inside. Element references are shared — not deep-cloned.

Example 4 — Shuffle Object Values

Plain objects become a shuffled array of values.

Lodash
_.shuffle({ a: 10, b: 20, c: 30 });
// → [20, 10, 30]   (example — values only)
Try It Yourself

How It Works

  1. Values. Lodash collects [10, 20, 30].
  2. Shuffle. Those values are permuted into a new array.
  3. No keys. Result is not an object — keys are dropped.
  4. Need pairs? Shuffle _.toPairs(obj) instead.

Example 5 — Empty Collection

Shuffling nothing yields an empty array.

Lodash
_.shuffle([]);
// → []
Try It Yourself

How It Works

  1. Empty source. Nothing to permute.
  2. Result. Returns [] — not undefined.
  3. Safe. No throw; loops over the result simply do nothing.
  4. vs sample. Empty _.sample → undefined; empty shuffle → [].

Browser & Runtime Support

_.shuffle is a Lodash 4.x Collection helper (since 0.1.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.1.0+

_.shuffle()

Available in [email protected] full builds and the lodash/shuffle modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.shuffle Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import shuffle from "lodash/shuffle" for smaller builds. Not a native browser API — load Lodash first.

Frequently Asked Questions

_.shuffle(collection) returns a new array with the collection's values in random order, using a Fisher-Yates shuffle. The original collection is not mutated.
No. It always returns a new array. Your source array, object, or string is left unchanged.
shuffle reorders every element. sampleSize(collection, n) returns only n unique random elements — prefer it when you do not need the full permutation.
Lodash shuffles the object's values into a new array. Keys are not preserved in the result.
No. It uses Lodash's pseudo-random helper, not crypto.getRandomValues. Do not use it for tokens, lotteries, or security-sensitive picks.
Use import shuffle from "lodash/shuffle" or require("lodash/shuffle") for tree-shaking. Full build: import _ from "lodash" then _.shuffle.

Next: _.size()

Get how many elements (or keys) a collection has.

_.size() tutorial →

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.

10 people found this page helpful