Swift - How to get indexes of filtered items of array

后端 未结 9 1157
旧巷少年郎
旧巷少年郎 2020-12-05 18:20
let items: [String] = [\"A\", \"B\", \"A\", \"C\", \"A\", \"D\"]

items.whatFunction(\"A\") // -> [0, 2, 4]
items.whatFunction(\"B\") // -> [1]
9条回答
  •  Happy的楠姐
    2020-12-05 18:39

    just copy and paste

    extension Array {
      func whatFunction(_ ids :  String) -> [Int] {
    
        var mutableArr = [Int]()
        for i in 0..

提交回复
热议问题