📜  如何从列表中快速删除项目代码示例

📅  最后修改于: 2022-03-11 15:01:00.104000             🧑  作者: Mango

代码示例1
var animals = ["cats", "dogs", "chimps", "moose"]

// remove at specific index
animals.remove(at: 2)  //["cats", "dogs", "moose"]

// remove first element
animals.removeFirst() //["dogs", "moose"]

// remove last element
animals.removeLast() //["dogs"]

// remove at unknown index
if let index = animals.firstIndex(of: "dogs") {
    animals.remove(at: index)
}