How to remove item in Array?

Solutions Collect From Internet About “How to remove item in Array?”

You are removing item at the same time when you are enumerating same array. Use filter instead:

var array: [Int] = [0,1,2,3,4,5]
array = array.filter{$0 != 2}

or, for multiple values, use Set:

let unwantedValues: Set<Int> = [2, 4, 5]
array = array.filter{!unwantedValues.contains($0)}

Same in one line:

array = array.filter{!Set([2, 4, 5]).contains($0)}