Lodash _.slice() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Creates a slice of array from start up to, but not including, end. Part of Lodash Array since 3.0.0 (stable in 4.x — not deprecated). Note: Lodash uses this instead of native Array#slice to ensure a dense array is returned.

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

Syntax

Call _.slice on an array. Start with this line.

Lodash
_.slice(array, [start=0], [end=array.length])
CallWhat it does
_.slice(array, [start=0], [end=array.length])Primary signature.
_.slice(array)Call with an array argument.

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

Library declarations
Lodash
_.slice(array, [start=0], [end=array.length])

Parameters

ParameterDescription
arrayRequired. Source to copy from
startOptional. First index to include; default 0
endOptional. Exclusive end; default array.length

Return Value

Return ValueDescription
*New dense array for that range

Lodash Examples

Example 1 — Slice From an Index

Omit end to copy from start through the last element.

Lodash
_.slice([1, 2, 3, 4], 2);
// → [3, 4]
Try It Yourself

How It Works

  1. Start at 2. Indexes 0 and 1 are skipped.
  2. Default end. End becomes 4 (array length).
  3. Copy. Indexes 2 and 3 → [3, 4].
  4. Safe. The original array is unchanged.

Example 2 — Start & End Range

Limit the window with an exclusive end.

Lodash
_.slice([1, 2, 3, 4], 1, 3);
// → [2, 3]
Try It Yourself

How It Works

  1. Range. Include from index 1; stop before 3.
  2. Kept. Values at indexes 1 and 2.
  3. Dropped. 1 (before start) and 4 (at end).
  4. Rule. Half-open interval [start, end).

Example 3 — Negative Start

Count backward from the end — same idea as native slice.

Lodash
_.slice([1, 2, 3, 4], -2);
// → [3, 4]
Try It Yourself

How It Works

  1. Resolve. -2 + 4 = 2 → start at index 2.
  2. Copy. From there to the end → [3, 4].
  3. Shortcut. Handy for “last two items” without computing length.
  4. Also. Negative end works the same way.

Example 4 — Shallow Clone

Omit both indexes to copy the whole array into a new reference.

Lodash
var nums = [1, 2, 3];
var copy = _.slice(nums);

console.log(copy);          // [1, 2, 3]
console.log(copy === nums); // false
Try It Yourself

How It Works

  1. Defaults. start = 0, end = length.
  2. New array. copy holds the same values in a new object.
  3. Identity. copy === nums is false.
  4. Shallow. Nested objects inside would still be shared.

Example 5 — Dense Copy of Sparse Array

Lodash returns a dense array — holes become defined undefined slots.

Lodash
var sparse = Array(3);
sparse[0] = "a";
sparse[2] = "c";
// sparse has a hole at index 1

var dense = _.slice(sparse);
console.log(1 in dense); // true  (slot exists)
console.log(dense[1]);   // undefined
Try It Yourself

How It Works

  1. Sparse source. Index 1 is a hole (1 in sparse is false).
  2. Lodash note. _.slice builds a dense result.
  3. Defined slot. 1 in dense is true; value is undefined.
  4. Why. Predictable iteration and JSON-like behavior after the copy.

Browser & Runtime Support

_.slice is a Lodash 4.x Array helper (since 3.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.prototype.slice is also available in all modern (and many older) JS engines.

✓ Stable · Lodash 3.0.0+

_.slice()

Available in [email protected] full builds and the lodash/slice 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
_.slice Lodash 3.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import slice from "lodash/slice" for smaller builds — or native array.slice() when you do not need Lodash’s dense-array guarantee.

Frequently Asked Questions

_.slice(array, [start=0], [end=array.length]) creates a new array with elements from start up to, but not including, end. The source array is not mutated.
No. End is exclusive — same rule as native Array.prototype.slice. slice(arr, 1, 3) keeps indexes 1 and 2 only.
Negative start or end counts from the end of the array. -1 is the last element, -2 is second-to-last, and so on.
Range rules match. Lodash’s note is that _.slice ensures a dense array is returned — useful when copying sparse arrays so holes become defined undefined slots.
No. Slice is shallow: nested objects or arrays inside the window share references with the original.
Use import slice from "lodash/slice" or require("lodash/slice") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.slice.

Next: _.sortedIndex()

Find where a value should be inserted to keep sort order.

_.sortedIndex() 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