String.slice

slice — Slices out a part of a string and returns it.

Description

String.slice(integer begin, [integer end])

Parameters

Name Description Type Default Optional
begin integer No
end integer Yes

Positive values count from beginning of string, whele negative count from the end.

Return values

string primitive.

Examples

Example #1 – slice example
console.log('Hello World'.slice(1)); // ello World console.log('Hello World'.slice(-1)); // d console.log('Hello World'.slice(1, -1)); // ello Worl console.log('Hello World'.slice(-4, -1)); // orl console.log('Hello World'.slice(0, 1)); // H

See also

External references