tail
Import from @varavel/vdl-plugin-sdk/utils/arrays.
Utility functions re-exported from es-toolkit (MIT License).
See https://github.com/toss/es-toolkit for more details.
Call Signature
function tail<T>(arr): [];
Returns an empty array when the input is a single-element array.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of the single element in the array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr | readonly [T] | The single-element array to process. |
Returns
[]
An empty array.
Example
const arr = [1];
const result = tail(arr);
// result will be []
Call Signature
function tail(arr): [];
Returns an empty array when the input is an empty array.
Parameters
| Parameter | Type | Description |
|---|---|---|
arr | readonly [] | The empty array to process. |
Returns
[]
An empty array.
Example
const arr = [];
const result = tail(arr);
// result will be []
Call Signature
function tail<T, U>(arr): U[];
Returns a new array with all elements except for the first when the input is a tuple array.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of the first element in the tuple array. |
U | The type of the remaining elements in the tuple array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr | readonly [T, U] | The tuple array to process. |
Returns
U[]
A new array containing all elements of the input array except for the first one.
Example
const arr = [1, 2, 3];
const result = tail(arr);
// result will be [2, 3]
Call Signature
function tail<T>(arr): T[];
Returns a new array with all elements except for the first.
This function takes an array and returns a new array containing all the elements except for the first one. If the input array is empty or has only one element, an empty array is returned.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of elements in the array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr | readonly T[] | The array to get the tail of. |
Returns
T[]
A new array containing all elements of the input array except for the first one.
Example
const arr1 = [1, 2, 3];
const result = tail(arr1);
// result will be [2, 3]
const arr2 = [1];
const result2 = tail(arr2);
// result2 will be []
const arr3 = [];
const result3 = tail(arr3);
// result3 will be []