Glossary Term
String.prototype.slice()
The slice() method of String values extracts a section of this string and returns it as a new string, without modifying the original string.
slice() extracts the text from one string and returns a new string.
slice() extracts up to but not including indexEnd. For example, str.slice(4, 8) extracts the fifth character through the eighth character (characters indexed 4, 5, 6, and 7):
If indexStart >= str.length, an empty string is returned. If indexStart < 0, the index is counted from the end of the string. More formally, in this case, the substring starts at max(indexStart + str.length, 0). If indexStart is omitted, undefined, or cannot be converted to a number, it’s treated as 0. If indexEnd is omitted or undefined, or if indexEnd >= str.length, slice() extracts to the end of the string. If indexEnd < 0, the index is counted from the end of the string. More formally, in this case, the substring ends at max(indexEnd + str.length, 0). If indexEnd <= indexStart after normalizing negative values (i.e., indexEnd represents a character that’s before indexStart), an empty string is returned.
Syntax example: slice(indexStart)
Term Connections
Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.
Loading term connections…
