substr()
String
instance method getterS2C Home
« Globals « String « substr()
Description
Returns the characters of a section of an existing string.
Syntax
Signature | Description |
---|---|
aString.substr(begin[, numChars]) | Returns the characters of a section of an existing string. |
Parameters
Parameter | Description |
---|---|
begin | The starting extraction position of the zero-based character index.
|
numChars | An integer specifying the number of characters to extract.
|
Examples
The code below returns part of a string.
// Create a string variable.
var anotherSong = 'I like sunshine, I like moonlight';
/*
Extract part of the string.
/*
alert(anotherSong.substr(2, 4));
/*
Extract another part of the string.
/*
alert(anotherSong.substr(6, 9));
Related Tutorials
JavaScript Basic Tutorials - Lesson 8 - Strings