Array.slice(start, [end]) Last updated: 22. Jul 2024
Returns a new array of a part of the array. Does not modify the existing array.
Parameters
Name | Type | Description |
---|---|---|
start | int | Index where to take items |
end (optional) | int | Index where to stop to return items |
Returns
An array of the items that were "sliced" out of the array.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
write(animals.slice(2));
/* Expected output: Array ["camel", "duck", "elephant"] */
Output
The JS code above produces the output shown below:["camel","duck","elephant"]