The .slice() array method returns a shallow copy of all or part of an array without modifying the original.


The returned array contains the element specified by the first argument and all subsequent elements up to, but not including, the element specified by the second argument.

  • start: The start index of the slice to be returned (optional)
  • end: The end index of the slice to be returned (optional)

If only one argument is specified, the returned array contains all elements from the start position to the end of the array.


If start and end values are not provided, the slicing of array will be of the whole array.


Two Arguments

To create a subarray of ['Tuesday', 'Wednesday', 'Thursday'] from weekDays array:


Negative Arguments

A negative index can be used, indicating an offset from the end of the sequence. For example:


To create the same subarray as the one above with negative index values:


One Argument

To create a subarray of the last two elements from weekDays:


Zero Arguments

To create an identical subarray of weekDays:

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn JavaScript on Codecademy