JavaScriptArrayslice
shift

sliceArray

some

Extracts a section of a string and returns it as a new string.

Syntax

arr.slice(start?, end?)

Example

Enter values below to update the example in real time.

const
arr
console
slice
const arr = [1, 2, 3, 4, 5];
console.log(arr.slice(1, 3));    // [2, 3]
console.log(arr.slice(-2));      // [4, 5]