Post

Slice To Get Last Characters Of String

Slice To Get Last Characters Of String

Syntax

The slice() method is a copying method.
It does not alter this but instead returns a shallow copy that contains some of the same elements as the ones from the original array.

1
2
3
slice()
slice(start)
slice(start, end)

start:
if start < 0, start + array.length is used.
if start < -array.length or start is omitted, 0 is used.
if start >= array.length, nothing is extracted.

end: extracts up to but not including end.
if end < 0, end + array.length is used.
if end < -array.length, 0 is used.
if end >= array.length or end is omitted, array.length is used, causing all elements until the end to be extracted.
if end is positioned before or at start after normalization, nothing is extracted.

This post is licensed under CC BY 4.0 by the author.