Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

dart create list from object properties

class City {
  const City(this.id, this.name);

  final int id;
  final String name;
}

List<City> cities = [
  City(0, 'A'),
  City(1, 'B'),
  City(2, 'C'),
];

final List<String> cityNames = cities.map((city) => city.name).toList();

void main() {
  print(cityNames);
}
 
PREVIOUS NEXT
Tagged: #dart #create #list #object #properties
ADD COMMENT
Topic
Name
5+7 =