take
arrayCreates a slice of array with n elements taken from the beginning.
Signature
take<T>(array: T[], n?: number): T[]Parameters
| Name | Type | Description |
|---|---|---|
array | T[] | The array to query |
n? | number | The number of elements to takeDefault: 1 |
Returns
T[] - Returns the slice of array
Examples
Take 1 element
import { take } from 'dashlite'
const result = take([1, 2, 3])
console.log(result)Output:
[1]Take multiple elements
import { take } from 'dashlite'
const result = take([1, 2, 3], 2)
console.log(result)Output:
[1, 2]Available since version 1.0.0