limit
limit(list: List<T>, n: Number) : List<T>
Gets the sublist of list consisting of the first n elements of list.
- The maximum number of elements to return,
n, must be non-negative. - If
nis greater than the collection size, returns all elements. - If
nis 0, returns an empty collection
Examples
Basic Usage
numbers = [1, 2, 3, 4, 5];
firstThree = limit(numbers, 3); // [1, 2, 3]
With order by Clause
limit(
foreach device in network.devices
select { Name: device.name }
order by Name desc,
10
)
Using Comprehension Syntax
The limit clause in a comprehension provides a more readable alternative:
foreach device in network.devices
select { Name: device.name }
order by Name desc
limit 10
See Also
Guides
- Collections - Comprehensive guide on Lists, Bags, and ordering
- Comprehensions - Using limit clause