slice

array

Creates a slice of array from start up to, but not including, end.

Signature

slice<T>(array: T[], start?: number, end?: number): T[]

Parameters

NameTypeDescription
arrayT[]The array to slice
start?numberThe start positionDefault: 0
end?numberThe end position

Returns

T[] - Returns the slice of array

Examples

Basic usage

import { slice } from 'dashlite'

const result = slice([1, 2, 3], 0, 2)
console.log(result)

Output:

[1, 2]

Available since version 1.0.0