| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
substr Method (String) (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
|
|
f12541c1-2623-482e-941d-2e22bc3c4a4a |
15 |
mikejo5000 |
mikejo |
ghogen |
Gets a substring beginning at the specified location and having the specified length.
stringvar.substr(start [, length ])
stringvar
Required. A string literal or String object from which the substring is extracted.
start
Required. The starting position of the desired substring. The index of the first character in the string is zero.
length
Optional. The number of characters to include in the returned substring.
If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of stringvar.
The following example illustrates the use of the substr method.
var s = "The quick brown fox jumps over the lazy dog.";
var ss = s.substr(10, 5);
document.write("[" + ss + "] <br>");
ss = s.substr(10);
document.write("[" + ss + "] <br>");
ss = s.substr(10, -5);
document.write("[" + ss + "] <br>");
// Output:
// [brown]
// [brown fox jumps over the lazy dog.]
// [] [!INCLUDEjsv3]
Applies To: String Object