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)
myString.slice()
myString.slice(start)
myString.slice(start, end)