How to remove an element from an array in Swift

后端 未结 18 2178
灰色年华
灰色年华 2020-11-28 18:38

How can I unset/remove an element from an array in Apple\'s new language Swift?

Here\'s some code:

let animals = [\"cats\", \"dogs\", \"chimps\", \"m         


        
18条回答
  •  佛祖请我去吃肉
    2020-11-28 18:51

    Few Operation relates to Array in Swift

    Create Array

    var stringArray = ["One", "Two", "Three", "Four"]
    

    Add Object in Array

    stringArray = stringArray + ["Five"]
    

    Get Value from Index object

    let x = stringArray[1]
    

    Append Object

    stringArray.append("At last position")
    

    Insert Object at Index

    stringArray.insert("Going", at: 1)
    

    Remove Object

    stringArray.remove(at: 3)
    

    Concat Object value

    var string = "Concate Two object of Array \(stringArray[1]) + \(stringArray[2])"
    

提交回复
热议问题