Slicing A String
Learn how to slice a string using the slice method.
We'll cover the following
The slice method
The slice
method is commonly used in simple functions and coding challenges. It returns a substring of the string specified by its argument list.
The easiest way to remember the parameter list of
slice
is:
str.slice(firstIndexInString)
or
str.slice(firstIndexInString, firstIndexAfterString)
The first argument of slice
specifies the position of the first character of the substring. The second argument is optional. When it is missing, slicing happens until the end of the string. When it is specified, it points at the first character after the sliced substring.
Get hands-on with 1200+ tech skills courses.