pluck method

List<T?> pluck(
  1. String key
)

The pluck method retrieves all of the values for a given key

Example:


list.pluck("id")

[
    {"id":1,"name":"Tony"},
    {"id":2,"name":"Thor"}
]

[1,2]

Implementation

List<T?> pluck(String key) {
  if (isEmpty) {
    return <T>[];
  }
  final List<T> result = <T>[];
  for (final T element in this) {
    if (element is Map<String, T> && element.containsKey(key)) {
      result.add(element[key] as T);
    }
  }
  return result;
}