.elementAt()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Mar 10, 2024
Contribute to Docs

In Dart, the .elementAt() method is used to access the element at a specific index in a list. The index needs to be a non-negative integer that’s smaller than the length of the list.

Syntax

list.elementAt(index);
  • list: The list that needs to be searched.
  • index: The index that needs to be accessed.

Example

Here is an example that demonstrates the use of the .elementAt() method:

void main() {
List nums = ['11', '22', '33', '44', '55'];
// Using the .elementAt() method to access the element at nums[2]
var num = nums.elementAt(2);
print('The element at nums[2] is: ${num}');
}

The output for the above example is:

The element at nums[2] is: 33

All contributors

Looking to contribute?

Learn Dart on Codecademy