Limit Array
Limit an array to a certain number of elements and return the remaining count.
Category | Arrays |
Author | Pol Gubau |
Since | 1.0.0 |
Last Updated | 2025-03-15 |
Type | Sync |
Compatibility | Universal |
Example
Input
limitArray([1, 2, 3, 4, 5], 3)
Output:
{ limitedArray: [1, 2, 3], remaining: 2 }
Return
An object containing the limited array and the count of remaining elements.
Type: { limitedArray: T[], remaining: number }
Props
Name | Type | Default | Required | Description |
---|---|---|---|---|
arr | T[] | null | Yes | The array to be limited. |
limit | number | 3 | No | The maximum number of elements to keep. |
Notes
If the array length is less than or equal to the limit, `remaining` will be 0.
Tags
- array
- limit
- slice