繁体   English   中英

如何循环遍历从不同索引开始的数组,同时仍然快速遍历整个数组?

[英]How to loop through arrays starting at different index while still looping through entire array in swift?

我想在索引处开始循环遍历数组(比如“5”或任何其他),而不是在 swift 中数组的开头

for (index, value) in array.enumerate() {
  // do something 
}

使用dropFirst忽略第一项:

for (index, value) in array.enumerated().dropFirst(5) {
    // your code here
}

使用where子句

for (index, value) in array.enumerate() where index > 4 { ...

顺便说一句:更新您的 Swift 版本。 斯威夫特 2 死了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM