JavaScript Array slice() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.slice(start?, end?) returns a new array with elements from start up to (but not including) end. The original array is never changed. Need to delete or insert in place? Use splice() instead.

Remember
array.slice(start, end)

end is exclusive
slice(1, 4) → indexes 1, 2, 3

slice()      → full shallow copy
slice(-2)    → last two elements
slice(0, -1) → all but the last

original array stays unchanged ✓

Syntax

Call array.slice. Start with this line.

JavaScript
array.slice(start?, end?)
CallWhat it does
array.slice(start?, end?)Primary signature.
array.slice(...)Call with the arguments your case needs.

Built into JavaScript. Call slice(...) on an array instance — no import required.

Library declarations
JavaScript
array.slice(start?, end?)

Parameters

ParameterDescription
ArrayRequired. Source to copy from (read-only)
startOptional. Inclusive start index (default 0)
endOptional. Exclusive end index (default length)

Return Value

Return ValueDescription
*The value returned by array.slice().

JavaScript Examples

Example 1 — Extract a Range (End Exclusive)

Take fruits from index 1 up to (not including) index 4.

JavaScript
const fruits = ["apple", "orange", "banana", "grape", "kiwi"];

const middle = fruits.slice(1, 4);

console.log(middle);
// ["orange", "banana", "grape"]
Try It Yourself

How It Works

  1. Pick the start. Index 1 is "orange" — included.
  2. Walk forward. Indexes 2 and 3 are copied next.
  3. Stop before end. Index 4 ("kiwi") is excluded because end is exclusive.
  4. New array only. middle is a fresh list; fruits is untouched.

Example 2 — Negative Indexes from the End

Use negative values to grab the last items or drop the last item.

JavaScript
const nums = [10, 20, 30, 40, 50];

console.log(nums.slice(-2));
// [40, 50]
console.log(nums.slice(0, -1));
// [10, 20, 30, 40]
Try It Yourself

How It Works

  1. Count from the end. Negative indexes add length first.
  2. Last two. -2 + 5 = 3 → from 40 to the end.
  3. Drop the last. end = -1 means stop before the final item.
  4. Source safe. nums stays [10, 20, 30, 40, 50].

Example 3 — Original Array Stays the Same

Slice a subset and confirm the source list is unchanged.

JavaScript
const colors = ["red", "green", "blue", "yellow"];

const subset = colors.slice(1, 3);

console.log("subset:", subset);
// ["green", "blue"]
console.log("original:", colors);
// ["red", "green", "blue", "yellow"]
Try It Yourself

How It Works

  1. Copy indexes 1–2. slice(1, 3) includes "green" and "blue".
  2. New reference. subset is a different array object.
  3. Source intact. colors still has all four items.
  4. Why it helps. Safe before passing data to code that must not mutate the original.

Browser & Runtime Support

Array.prototype.slice() has been part of JavaScript since ES3 / JavaScript 1.2. It is one of the most widely available array helpers.

✓ Baseline · ES3

Array.prototype.slice()

Supported in every major browser (including Internet Explorer) and all Node.js versions. No polyfill required.

100% Universal support
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
Array.slice() Excellent

Bottom line: Safe everywhere. Prefer slice whenever you need a non-mutating extract or a simple shallow copy.

Frequently Asked Questions

slice() returns a new array containing elements from start index up to (but not including) end index. The original array is not changed.
No. slice() always returns a new array. The source array keeps the same elements and order.
No. end is exclusive. slice(1, 4) includes indices 1, 2, and 3—not index 4.
Negative start or end counts from the end of the array. slice(-2) takes the last two elements. slice(0, -1) takes all but the last.
slice() extracts without mutating. splice() removes or inserts elements in the original array and returns the removed items.
slice() has been available since JavaScript 1.2 / ES3. It works in every browser, including very old environments.

Next: some()

Learn how to test whether at least one element passes a condition.

some() 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.

12 people found this page helpful