How to remove an element of a given value from an array in Swift

I want to remove all elements of value x from an array that contains x, y and z elements

let arr = ['a', 'b', 'c', 'b']

How can I remove all elements of value 'b' from arr?


Solution 1:

A filter:

 let farray = arr.filter {$0 != "b"} 

Solution 2:

var array : [String]
array = ["one","two","one"]

let itemToRemove = "one"

while array.contains(itemToRemove) {
    if let itemToRemoveIndex = array.index(of: itemToRemove) {
        array.remove(at: itemToRemoveIndex)
    }
}

print(array)

Works on Swift 3.0.