slice() method is a powerful tool for manipulating strings. It can extract parts of a string and return the extracted parts in a new string.
slice() method accepts two arguments: the start position, and the end position (optional). If the end position is omitted, the method slices out the rest of the string.
slice() with positive indexes
Positive indexes represent positions at the start of the string. The first character is at position
slice() with negative indexes
Negative indexes represent positions at the end of the string. The last character is at position
If you omit the second argument,
slice() will return the rest of the string.
All modern browsers fully support the
Join our community of forward-thinkers and innovators. Subscribe to get the latest updates on courses, exclusive insights, and tips from industry experts directly to your inbox.