1恨豁、list的遍歷
var list = [1, 2, 3, 4, 5];
for (var i = 0; i <list.length; i++) {
print(list[i]);
}
for (var item in list) {
print(item);
}
list.forEach((element) {
print(element);
});
//where判斷大于3,返回值為(4,5),toList()組成新的list
var newList = list.where((element) => element > 3).toList();
print(newList);
//any 判斷l(xiāng)ist的數(shù)據(jù)是否有大于3的值爬迟,返回值為bool橘蜜,true
var checkAny = list.any((element) => element > 3);
print(checkAny);
//every 判斷l(xiāng)ist里面的數(shù)據(jù)是否都大于3,返回值為bool, false
var checkEvery = list.every((element) => element > 3);
print(checkEvery);
2付呕、map的遍歷
var map = {
"name":"張三",
"age":22,
"work":"上班族",
"sex":"男",
};
for(var item in map.keys){
print(item);
}
for(var item in map.values){
print(item);
}
map.forEach((key, value) {
print("$key---$value");
});
var newList = map.values.where((element) => element==22);
print(newList.toList());
//判斷map的值是否有張三计福,返回值bool
var checkAny = map.values.any((element) => element=="張三");
print(checkAny);
//判斷map的值是否全部為張三,返回值bool
var checkEvery = map.values.every((element) => element=="張三");
print(checkEvery);