Convert List<Class> to List<Class.property>

Viewed 187

I am looking for an elegant way to convert a List where we remove the object information and keep only a specific property.

example: List< Fruit> becomes List with the property fruitColor (a String) kept.

1 Answers

I think you're looking for:

var listOfFruit = ...;
var listOfColors = listOfFruit.map((e) => e.fruitColor).toList();
Related