Array.slice

slice — Copies a piece out of an array and returns it.

Description

Array.slice([integer begin, [integer end]])

Parameters

Name Description Type Default Optional
begin integer Yes
end integer Yes

Return values

The copied piece of the array.

Examples

Example #1 – slice example
var array = [2, 4, 8, 16, 32, 64]; console.log(array.slice()); // [2, 4, 8, 16, 32, 64] console.log(array.slice(2)); // [8, 16, 32, 64] console.log(array.slice(2, 2)); // [] console.log(array.slice(2, 5)); // [8, 16, 32] console.log(array); // [2, 4, 8, 16, 32, 64]

External references