Removing objects from an array based on another array

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

I have two arrays like this:

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

9条回答
  •  不要未来只要你来
    2021-02-05 01:29

    I agree with Antonio's answer, however for small array subtractions you can also use a filter closure like this:

    let res = arrayA.filter { !contains(arrayB, $0) }
    

提交回复
热议问题