JavaScript String slice() method
returns the extracted part of a string into a new string

slice() method extracts a part of a string and returns it as a new string, without modifying the original string.

syntax

slice(start, end)

start The index of the first character to include in the returned substring.

end (optional). The index of the first character to exclude from the returned substring.

The first position is 0, the second is 1, ...

slice() method returns the extracted part in a new string.

slice() method does not change the original string.

The start and end parameters specifies the part of the string to extract.

A negative number selects from the end of the string.

To remove first character from a string: myString.slice(1)

To remove first and last characters from a string: myString.slice(1, -1)

syntax 1 description
return a shallow copy of myString
myString.slice()
syntax 2 description
return a new string from start index to end of myString
myString.slice(start)
syntax 3 description
return a new string from start index to end index of myString
myString.slice(start, end)