takeRight
arrayCreates a slice of array with n elements taken from the end.
Signature
takeRight<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 from end
import { takeRight } from 'dashlite'
const result = takeRight([1, 2, 3])
console.log(result)Output:
[3]Take multiple from end
import { takeRight } from 'dashlite'
const result = takeRight([1, 2, 3], 2)
console.log(result)Output:
[2, 3]Available since version 1.0.0