Get index in ForEach in SwiftUI

Another approach is to use:

enumerated()

ForEach(Array(array.enumerated()), id: \.offset) { index, element in
  // ...
}

Source: https://alejandromp.com/blog/swiftui-enumerated/

Leave a Comment