The index refers to the item's position in the ordered list, and a single element is retrieved from the array using the subscript syntax array[index]
.
var vowels = ["a", "e", "i", "o", "u"]
print(vowels[0]) // prints: a
print(vowels[1]) // prints: e
print(vowels[2]) // print: i
print(vowels[3]) // prints: o
print(vowels[4]) // prints: u
Note: Swift arrays are zero-indexed, meaning the first element has index 0.
Comments