Check If Array Contains Value Swift

[Solved] Check If Array Contains Value Swift | Swift - Code Explorer | yomemimo.com
Question : check if array contains value swift

Answered by : lmaocoder

//we can use the .contains element
//Declaration:
func contains(_ element: Element) -> Bool
//Thus, it accepts an array and a value, and checks if the value if present in the array
//Example:
sampleArray = ["Apple", "Berry", "Banana"]
print(sampleArray.contains("Apple"))
//The contains function checks in the sampleArray if an element called Apple exists. If it exists, it prints true.
//Therefore prints true

Source : https://developer.apple.com/documentation/swift/array/2945493-contains | Last Update : Thu, 19 Aug 21

Answers related to check if array contains value swift

Code Explorer Popular Question For Swift