0Pricing
Dart Academy · Lesson

Enum Values, index, and name

Iterate and inspect enum members.

Enums Know Their Members

Every enum quietly tracks all of its members for you. Dart gives you built-in ways to list, count, and inspect them.

The values List

Each enum has a static values list holding every member in order. It is your gateway to looping over an enum.

enum Color { red, green, blue }
print(Color.values); // [Color.red, ...]

All lessons in this course

  1. Declaring and Using Plain Enums
  2. Enum Values, index, and name
  3. Enhanced Enums With Fields and Methods
  4. switch Over Enums Exhaustively
← Back to Dart Academy