Skip to main content

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 n is greater than the collection size, returns all elements.
  • If n is 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

Functions

  • orderBy - Sort a collection by a key function
  • length - Get the length of a collection