Favorites

JavaScript String.prototype.slice() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.slice()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The slice() method extracts part of a string between two indexes and returns it as a new string. Negative indexes count from the end.

Description

The slice() method extracts a section of a string, from start up to but not including end, and returns it as a new string. Negative values count from the end, so slice(-3) gives the last three characters. It's generally preferred over substring() because of that negative-index support.

If start is greater than or equal to end, the result is an empty string; unlike substring(), the arguments are never swapped. Indexes count UTF-16 code units, so slicing in the middle of an emoji can leave half a character behind.

Common patterns include str.slice(0, n) to take the first n characters, str.slice(n) to drop them, and combining it with indexOf() to cut a string at a separator. Arrays and typed arrays have slice() methods with the same behavior.

Syntax

string.slice(start)
string.slice(start, end)

Parameters

  • startThe index to start at. Negative values count from the end.
  • endOptional. The index to stop before. Negative values count from the end.

Return Value

A new string containing the extracted part.

Example

const s = 'JavaScript';
console.log(s.slice(4));
console.log(s.slice(0, 4));
console.log(s.slice(-6, -3));

Browser Support

The following information will show you the current browser support for the String.prototype.slice() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee