Bruno Dias
Bruno Dias

Reputation: 149

How can I get items from a list from a specific index?

How can I get only the items ahead of a specified index in a list? Example:

var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
print(numbers[3..]);

Output: 4, 5, 6, 7, 8, 9, 10

Upvotes: 0

Views: 431

Answers (1)

Mattia
Mattia

Reputation: 6544

You can use the skip method, to skip a number of elements at the start of a List, for example:

var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
print(numbers.skip(3)); //Returns an iterable: (4, 5, 6, 7, 8, 9, 10)

Upvotes: 2

Related Questions