

Javascript slice() method with negative indexes That means string.slice(1, 6) extracts the second character through the sixth character (characters indexed 1, 2, 3, 4, 5). The Javascript string slice() method extracts up to but not including the endIndex. Use the negative numbers to select from the end of the string.

If we omit the endIndex parameter, the slice() function selects all characters from the start position to the end of the string. The endIndex argument is optional - the position (up to, but not including) where to end the extraction. We can use the negative values to specify the position from the end of the string. It is the position where to begin the extraction. string.slice(startIndex, endIndex) Parameters The syntax for the string slice method is the following.

The changes to the text in one string do not affect the other.
