Loop through array with index

 Problem

I have an array and want to iterate through all of its elements, by knowing the index of each element.



 Recipe


// Initialize the Array
var arr = ["one", "two", "three"]

// Iterate through the array
// keeping track of the elements' index

for (index,element) in arr.enumerate() {
    print("\(index) = \(element)")
}

				


 Playground