Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

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

A filter:

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

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.

Tags:

Swift

Related

How do ASCII Adjust and Decimal Adjust instructions work? Conform to protocol in ViewController, in Swift Is key-value observation (KVO) available in Swift? Laravel 4.2 says my application is in production. How do I turn this off? How to convert Any to Int in Swift Checking if an object is a given type in Swift How to add row group headers to a "headerless" style report? Why Pandoc does not retrieve the image file? How to add multiple strings to a set in Python? Swift - Split string over multiple lines How to convert a swift String to CFString How can I test that a value is "greater than or equal to" in Jasmine?

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy