Array methods
Array.prototype.slice()
Copies a range shallowly, without mutating the receiver. End is excluded; negative indices are relative to length. Omitted end extends to length. Holes are preserved in ordinary sparse arrays.
Formal Syntax & Structure
javascript syntaxjavascript
array.slice(start, end)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| start | Number | Inclusive start; defaults to zero. |
| end | Number | Exclusive end; defaults to length. |
Return Value
Array
Shallow selected range.
Working Example
Example Snippetjavascript
const a=[1,2,3];console.log(a.slice(-2).join(","),a.length);