Removing objects from an array based on another array

前端 未结 9 1478
南方客
南方客 2021-02-05 01:14

I have two arrays like this:

var arrayA = [\"Mike\", \"James\", \"Stacey\", \"Steve\"]
var arrayB = [\"Steve\", \"Gemma\", \"James\", \"Lucy\"]

9条回答
  •  旧时难觅i
    2021-02-05 01:40

    Like this:

    var arrayA = ["Mike", "James", "Stacey", "Steve"]
    var arrayB = ["Steve", "Gemma", "James", "Lucy"]
    for word in arrayB {
        if let ix = find(arrayA, word) {
            arrayA.removeAtIndex(ix)
        }
    }
    // now arrayA is ["Mike", "Stacey"]
    

提交回复
热议问题