SLICE
Overview
The SLICE function is used to extract a subset from an array. Based on the specified starting position (start) and the desired number of elements (limit), the function will return a new array containing up to limit elements. If the specified starting position is a negative number, the position is calculated from the end of the array.
Syntax
Parameters
array
: Typearray<T>
, represents the array to be sliced.start
: Type int, indicates the starting position of the slice. Counting starts from 1. If start is negative, counting starts from the end of the array.limit
: Type int, indicates the number of elements to extract. If this parameter is omitted, all elements from the start position will be returned.
Return
Returns a new array containing up to limit elements starting from the start position.
Example
- Extract the first two elements from the array:
Results:
- Extract an element starting from the third element of the array:
Results:
Notes
- If the values of start and limit exceed the array range, the function will return an empty array.