sub

英[sʌb] 美[sʌb]

n.submarine;substitute,substitute,substitute;subway;reviewer

vi.Be a substitute, be a substitute player; be a substitute, review (manuscript)

Third person singular: subs Plural: subs Present participle: subbing Past tense: subbed Past participle: subbed

string

英[strɪŋ] 美[strɪŋ]

n.String; rope, belt; thread, plant fiber; [Computer Science] character string

vt. to string, tune; to line up in a row or a series; to tie, tie or hang with a thread; to extend or expand

Third person singular: strings Plural: strings present participle : stringing past tense: strung past participle: strung

javascript substr() method syntax

Function: Extract the specified number of characters starting from the start subscript in the string.

Syntax: stringObject.substr(start,length)

Parameters: start Required . The starting index of the substring to be extracted. Must be a numeric value. If negative, this parameter declares the position from the end of the string. That is, -1 refers to the last character in the string, -2 refers to the second to last character, and so on. length is optional. The number of characters in the substring. Must be a numeric value. If this parameter is omitted, the string from the beginning to the end of stringObject is returned.

Return: A new string containing length characters starting from stringObject's start (including the character pointed to by start). If length is not specified, the returned string contains characters from start to the end of stringObject.

Note: The parameters of substr() specify the starting position and length of the substring, so it can be used instead of substring() and slice().

javascript substr() method example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    var str="Hello world!"
    document.write(str.substr(3))

</script>

</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance