getByField<T> method
Returns a new list of values from the specified fieldName in a map-like structure.
The fieldName parameter represents the field name/key to extract from each map-like entry in the list.
The function maps over the entries in the list and retrieves the value associated with the fieldName.
Returns a new list containing the values from the specified fieldName.
Example:
List<Map<String, dynamic>> entries = [
{'name': 'Alice', 'age': 25},
{'name': 'Bob', 'age': 30},
{'name': 'Charlie', 'age': 35},
];
List<String> names = entries.getByField<String>('name');
print(names); // Output: [Alice, Bob, Charlie]
Implementation
List<T> getByField<T>(String fieldName) {
List<T> list = this.entries.map<T>((e) {
return e.value[fieldName];
}).toList();
return list;
}