I have a list of Foo
List<Foo> fooList = [
Foo("Zero", 0.0, 0.0],
Foo("One", 1.0, 0.0],
Foo("Two", 0.0, 1.0],
Foo("Three", 1.0, 1.0],
];
class Foo {
String name;
double bar;
double baz;
Foo(this.name, this.bar, this.baz);
}
Is there an easy way to extract and make a list of only baz?
I’ve made it work with a for-loop
List<double> values = <double>[];
for(var item in fooList) {
values.add(item.baz);
}
but I am hoping there are easier ways than that. Something like List<double>.from<fooList.baz>)
>Solution :
Yes you can simply do this by mapping.
final bazList = fooList.map((fooListItem) => fooListItem.baz)).toList();
bazList is a new array of baz items from the sequence of fooList