ios 判断数组有没有这个数据
在iOS中,可以使用contains()方法来判断一个数组是否包含某个元素。以下是一个示例:
let array = [1, 2, 3, 4, 5]
let element = 3
if array.contains(element) {
print("数组包含该元素")
} else {
print("数组不包含该元素")
}
在上面的例子中,array.contains(element)用于判断数组array是否包含元素element。如果包含,则输出"数组包含该元素",否则输出"数组不包含该元素"。
原文地址: http://www.cveoy.top/t/topic/iY8X 著作权归作者所有。请勿转载和采集!