Standard built-ins

String.prototype.slice()

Try the free JavaScript compiler

Extracts the half-open range; negative indices count from the end. A reversed normalized range returns empty.

Formal Syntax & Structure

javascript syntaxjavascript
text.slice(start, [end])

Parameters & Attributes

NameTypeDescription
startNumberStarting code-unit offset.
endNumberExclusive end offset; defaults to length.

Return Value

String

Extracted code-unit sequence.

Working Example

Example Snippetjavascript
console.log("abcdef".slice(-3,-1));
JavaScript Reference