The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters. Tip: To extract characters from the end of the string, use a negative start number (This does not work in IE 8 and earlier). Note: The substr() method does not change the original string.
The index of the first character to include in the returned substring. The index of the first character to exclude from the returned substring. A new string containing the specified part of the given string.
The slice method also expects the same two parameters: If we don’t set an ending index, then we get a substring starting from the given index number until the end of the original string: If we set both the startIndex and the endIndex, then we will get the characters between the given index numbers of the original string:
The substr () method returns a portion of the string, starting at the specified index and extending for a given number of characters afterwards. The index of the first character to include in the returned substring. Optional.
Which is part of the string does substring ( ) return?
The substring() method returns the part of the string between the start and end indexes, or to the end of the string.