/

HTML / CSS / JavaScript Tutorial

JavaScript String method: slice()

[this page | pdf | back links]

The slice() method (when applied to a JavaScript string) returns a new string formed by a part of the original string.

 

It has the following syntax with the following parameters:

 

string.slice(n1,n2)

 

Parameter

Required / Optional

Description

n1

Required

Position from where to begin extraction. 0 corresponds to the first character.

n2

Optional

(default is, in effect, string.length). Where to end extraction, so if omitted will select all characters from the n1’th position to the end of the string

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript String Variables


Desktop view | Switch to Mobile