slice (String - JavaScript)

Gets a substring starting and optionally ending at specified positions.

Defined in

String (Standard - JavaScript)

Syntax

slice(start:int) : string

slice(start:int, end:int) : string

Parameters Description
start The beginning index, inclusive, where 0 is the first index in the string.
end The ending index, exclusive. Defaults to the rest of the string.
Return value Description
string The substring.

Examples

(1) This example displays Moscow Tokyo (index 8 to the end).
var cities = new String("Paris   Moscow   Tokyo");
cities.slice(8)

(2) The following example prints Moscow (index 8 to index 14, exclusive).

var cities = new String("Paris   Moscow   Tokyo");
cities.slice(8, 14)