Now that we have an array, how do we retrieve an individual value? This is where index comes into play.
An index refers to an item’s position within an ordered list. Arrays in Swift are zero-indexed, meaning the first item has index 0, the second index 1, and so on.
var vowels = ["a", "e", "i", "o", "u"]
To retrieve individual elements, we can use the subscript syntax,
array[index]. The subscript syntax uses square brackets,
], around an index value.
print(vowels) // Prints: a print(vowels) // Prints: e print(vowels) // Prints: i print(vowels) // Prints: o print(vowels) // Prints: u
The 24-hour weather forecast is recorded in an array called
temperature, starting with the current temperature as its first value.
Print the current temperature using its index.