0

I want to get the value of 'id' of map as list.

Expected output: [1,35, 93, 82, 28]

[{'id': 1, 'name':'flutter', 'title':'dart'},

{'id': 35, 'name':'flutter', 'title':'dart'},

{'id': 93, 'name':'flutter', 'title':'dart'},
  
{'id': 82, 'name':'flutter', 'title':'dart'},

{'id': 28, 'name':'flutter', 'title':'dart'},
];

1 Answer 1

2

You can use .map to iterate through each object and get the value you want:

void main() {
  final list = [
    {'id': 1, 'name': 'flutter', 'title': 'dart'},
    {'id': 35, 'name': 'flutter', 'title': 'dart'},
    {'id': 93, 'name': 'flutter', 'title': 'dart'},
    {'id': 82, 'name': 'flutter', 'title': 'dart'},
    {'id': 28, 'name': 'flutter', 'title': 'dart'},
  ];

  final idList = list.map((e) => e['id']).toList(); // [1, 35, 93, 82, 28]
}

Sign up to request clarification or add additional context in comments.

2 Comments

The answer was helpful. Thank you :)
@lhyojin0821 if it solved your issue please mark it as accepted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.