Home > Back-end >  How to join two key values from map in dart?
How to join two key values from map in dart?

Time:05-07

I have this List<Map>:

var listMap = [
        {
          "label": "Title",
          "align": "left",
          "width": 50
        },
        {
          "label": "Date Created",
          "align": "left",
          "width": 50
        },

];

I want to join label, align and width with | So the final result is of type List<String> :

var finalResult = ["Title|left|50", "Date Created|left|50"];

How can i achieve finalResult?

CodePudding user response:

I have tried this

var listMap = [
        {
          "label": "Title",
          "align": "left",
          "width": 50
        },
        {
          "label": "Date Created",
          "align": "left",
          "width": 50
        },

];
  var newList = [];
  for (var e in listMap) {
    newList.add(e.values.join('|'));
  }
  print(newList);

Also @pskink answer is correct to!

  • Related