The `elementAt` method in Dart returns the index-th element.
The syntax of Runes.elementAt() method is:
int elementAt(int index)
This elementAt() method of Runes returns the index
th element.
Parameter | Optional/Required | Description |
---|---|---|
index | required | The index of the element to retrieve. |
Runes.elementAt() returns value of type int
.
In this example,
numbers
containing integers.elementAt()
method with index 1 to retrieve the second element.void main() {
List<int> numbers = [1, 2, 3];
int element = numbers.elementAt(1);
print(element);
}
2
In this example,
characters
containing characters.elementAt()
method with index 2 to retrieve the third element.void main() {
List<String> characters = ['a', 'b', 'c'];
String element = characters.elementAt(2);
print(element);
}
c
In this example,
words
containing strings.elementAt()
method with index 0 to retrieve the first element.void main() {
List<String> words = ['hello', 'world'];
String element = words.elementAt(0);
print(element);
}
hello
In this Dart tutorial, we learned about elementAt() method of Runes: the syntax and few working examples with output and detailed explanation for each example.