It is ordered collection of values
var randomWords: [String] = ["hello", "world", "fox", "cat", "dog"]
var marks: [Int] = [5, 6, 1, 10, 3]
//returns boolean indicating whether array is empty or not
print(randomWords.isEmpty)
//return no. of elements in the array
print(randomWords.count)
//returns first element, if empty returns "" string
print(randomWords.first ?? "")
//return maximum number of array
print(marks.max() ?? 0)
//return minimum number of array
print(marks.min() ?? 0)
Output
false 5 hello 10 1
you can select index and value by using enumerated.
for (key, value) in randomWords.enumerated() {
print("\(key) - \(value)")
}
Output