Home > Enterprise >  How to remove an element in a nested map (Flutter Dart)
How to remove an element in a nested map (Flutter Dart)

Time:04-01

I have a nested map as follows:

Map x = {
  'A' : {
    'name' : 'Will',
    'age' : 60
  },
  'B' : {
    'name' : 'Smith',
    'age' : 57
  }
};

So I just want to remove the age at B only and it will be like this:

{A: {name: Will, age: 60}, B: {name: Smith}}

I'm not sure how to use .removeWhere for nested maps.

CodePudding user response:

I think the most obvious solution is this:

x['B'].remove('age');

CodePudding user response:

you just need to use .remove function of list

list['B'].remove('age');

output

output log

  • Related