thumbnail

List Access Operator In Dart

Published on 29 March 2020
Last Updated on 29 March 2020

List access operator [] is used for referring to an element in the list using its index value.

Example that demonstrates use of List access operator

main(List<String> args) {
  // defining a new list of numbers
  var someList = [1, 2, 3, 4];

  // defining element using the list access operators
  var element = someList[1];
  print('element is ${element}');
}

Above program produces following output:

element is 2

As shown in above program, list access operator is used as follows:

var element = someList[1];