arrays - 仅当在 if 语句颤动中返回多个时才限制为 1
问题描述
假设我有一个给定的数组列表
Array listarray = ['1','2','3','3','3','4','5','6','6','7','8']
for (int i = 0; i<listarray.length; i++){
if(listarray[i] == '3'){
return 'this is three';
}else if (listarray[i] == '6'){
return 'this is six';
}
}
它将返回为
this is threethis is threethis is threethis is sixthis is six
我想知道是否有办法让我只退回第一个或将其限制为仅退回 1 个?
这样它就会像
this id threethis is six
解决方案
首先:dart中没有Array类型,但有List。
您可以通过将列表转换为设置来删除重复项:
var listarray = ['1','2','3','3','3','4','5','6','6','7','8'];
listarray = listarray.toSet().toList();
推荐阅读
- php - 如何在 Datatables 服务器端处理中实现 Ajax 调用
- flutter - 查看 Flutter 网站时不显示自定义字体
- datetime - ASP CORE 动态更新 viewbag 日期标题
- debian - Debian 存储库失败
- python - 如何删除 numpy 数组中的非对称对?
- r - 具有嵌套随机效应的 lmer 模型的预测
- node.js - node.js 服务器出现错误:在 godaddy vps linux 服务器中使用端口 80 或 443 而不是 3000 时,监听 EACCES:PERMISSION denied 0.0.0.0.80
- eucalyptus - 成像后端在桉树中不起作用
- python-3.x - 可迭代的Python多处理更新大小
- c - 用于计算的 C 中的二叉树实现