SomeGuyCalledBill
SomeGuyCalledBill

Reputation: 17

Dart Adding a new key value to map

How do I add a new key value to an existing map? I've searched but nowhere seem to answer for my example. My map looks like this:

myMap = {A: {b:3}}

I'm simply trying to add key values into 'A' so it looks like this:

{A: {b:3, c:3}}

Hope that makes sense!

Upvotes: 0

Views: 681

Answers (2)

Peter Koltai
Peter Koltai

Reputation: 9734

void main() {
  var myMap = {'A': {'b':3}};
  myMap['A']!['c'] = 3;
  print(myMap);
}

Upvotes: 2

APEALED
APEALED

Reputation: 1663

Assuming you started with:

var myMap = {'A': {'b': 3}};

You can update like this:

myMap['A'] = {
  'b': 3,
  'c': 3,
 };

Upvotes: 1

Related Questions