Flutter/Dart 문법
[Dart] List/map에 where사용해보기(where로 필터링)
Chafle
2023. 3. 23. 17:27
반응형
void main() {
List<Map<String, String>> idol = [
{'name': '민지', 'group': '뉴진스'},
{'name': '혜린', 'group': '뉴진스'},
{'name': 'RM', 'group': 'BTS'},
{'name': '뷔', 'group': 'BTS'},
{'name': '하니', 'group': '뉴진스'},
];
print(idol);
final newjeans = idol.where((x) => x['group'] == '뉴진스').toList();
final bts = idol.where((x) => x['group'] == 'BTS').toList();
print(newjeans);
print(bts);
}
where로 조건을 걸고 List로 도출해 낼 수 있다.
반응형