Should I prefer to iterate over Map.entries or Map.values?

We should iterate map based on the requirement.

  1. If we required to iterate only keys

    map.keys.forEach((k) => print("Key : $k"));

  2. If we required to iterate only values

    map.values.forEach((v) => print("Value: $v"));

  3. If we required to iterate both key values.

    map.forEach((k, v) => print("Key : $k, Value : $v"));

Leave a Comment