Skip to content

Latest commit

 

History

History
73 lines (57 loc) · 2.24 KB

File metadata and controls

73 lines (57 loc) · 2.24 KB
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
substring Method (String) (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
substring
JavaScript
TypeScript
DHTML
substrings
substring method
9cf9a005-cbe3-42fd-828b-57a39f54224c
18
mikejo5000
mikejo
ghogen

substring Method (String) (JavaScript)

Returns the substring at the specified location within a String object.

Syntax

  
      strVariable. substring(start [, end])  
"String Literal".substring(start [, end])   

Parameters

start
Required. The zero-based index integer indicating the beginning of the substring.

end
Optional. The zero-based index integer indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end.

If end is omitted, the characters from start through the end of the original string are returned.

Remarks

The substring method returns a string containing the substring from start up to, but not including, end.

The substring method uses the lower value of start and end as the beginning point of the substring. For example, strvar.substring(0, 3**)** and strvar.substring(3, 0) return the same substring.

If either start or end is NaN or negative, it is replaced with zero.

The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in strvar.substring(0, 3) and strvar.substring(3, 0) is three.

Example

The following example illustrates the use of the substring method.

var s = "The quick brown fox jumps over the lazy dog.";  
var ss = s.substring(10, 15);  
document.write(ss);  
  
// Output:  
// brown  
  

Requirements

[!INCLUDEjsv1]

See Also

substr Method (String)