List a = [3,5,7]
List b = [apple, banana, cake, coke, car, train, dog, paper]
output: coke, train, paper
Any function in Dart can achieve this ?
CodePudding user response:
Try this
List<int> a = [3, 5, 7];
List<String> b = [
'apple',
'banana',
'cake',
'coke',
'car',
'train',
'dog',
'paper'
];
List newList = a.map((e) => b[e]).toList();
print(newList);
More info on map
https://api.dart.dev/stable/2.16.2/dart-core/Iterable/map.html