List Use the array-like Dart List to manage a collection of objects

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access


*Enrollment provides full access to this course (and updates) for life.

Basic Lists

file_type_dartlang lists.dart
List<int> list = [1, 2, 3, 4, 5];

list[0]; // 1

list.length; // 5
list.last; // 5
list.first; // 1


file_type_dartlang lists.dart
  for (int n in list) {

list.forEach((n) => print(n));

var doubled = => n * 2);

Spread Syntax

file_type_dartlang lists.dart
var combined = [...list, ...doubled];

Conditions in Lists

file_type_dartlang lists.dart
bool depressed = false;
var cart = [
    if (depressed) 'Vodka'


Ask questions via GitHub below OR chat on Slack #questions