我的 Controller 中有以下代码。如何访问每个索引?
def arr = ['a', 'b', 'c']
arr.each
{
// 'it' is the element
println it
}
最佳答案
您可以使用 eachWithIndex :
arr.eachWithIndex { obj, i ->
println "${i}: ${obj}"
}
关于groovy - 每个 Grails 索引,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13786575/