Swift – Array找值/從集合找尋成員 | firstIndex | contains | filter 2020 年 9 月 15 日1 Min Read 0 0Array找值/從集合找尋成員 單純尋找Array裡面是否有值回傳Bool 尋找Array裡面是否有值回傳Index測試資料Arrayvar testList = ["測試1","測試2","測試3","測試4","測試5"] 尋找值回傳Boolif testList.contains("測試2"){ print("找到了") } 尋找值並回傳Indexif let index = testList.firstIndex(of: "測試2"){ print(index) } 相關Categorized in:swiftTagged in: array, contains, filter, firstIndex, list, 找值Share Article: