How to enumerate items in an array

How to enumerate items in an array

There several ways to loop through an array in Swift, but using the enumerated() method is one of my favorites because it iterates over each of the items while also telling you...

Alok Choudhary
Austin, TX
1 min read

There several ways to loop through an array in Swift, but using the enumerated() method is one of my favorites because it iterates over each of the items while also telling you the items’ position in the array.

Here’s an example: [swift] //How to enumarate a array let array = [“Hulk”, “Spidy”, “Thor”]

for (index, item) in array.enumerated() { print(“Found \(item) at position \(index)”) } [/swift]

That will print “Found Hulk at position 0”, “Found Spidy at position 1”, and “Found Thor at position 2”.

Link copied to clipboard!

Made with ❤️ in Austin.

Copyright © 2026