groovy Grails index每个

bttbmeg0  于 2024-01-06  发布在  其他
关注(0)|答案(1)|浏览(204)

我的控制器中有以下代码。我如何访问每个索引?

  1. def arr = ['a', 'b', 'c']
  2. arr.each
  3. {
  4. // 'it' is the element
  5. println it
  6. }

字符串

frebpwbc

frebpwbc1#

您可以使用eachWithIndex:

  1. arr.eachWithIndex { obj, i ->
  2. println "${i}: ${obj}"
  3. }

字符串

相关问题