arrays - Swift Array 实例方法 drop(at : Int)

标签 arrays swift slice sub-array

Array in Swift有几个排除元素的实例方法,比如dropFirst() , dropLast() , drop(while:)等等。 drop(at:) 呢?

注意:我会使用 remove(at:) ,但我正在使用的数组是一个 let 常量。

最佳答案

Note: I'd use remove(at:), but the array I'm working with is a constant.

我不会让那阻止你:

extension Array {
    func drop(at:Int) -> [Element] {
        var temp = self
        temp.remove(at: at)
        return temp
    }
}
let numbers = [1, 2, 3, 4, 5]
print(numbers.drop(at: 2)) // [1, 2, 4, 5]

关于arrays - Swift Array 实例方法 drop(at : Int),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52350697/

相关文章:

javascript每次覆盖数组对象

python - 用 Beautiful Soup 抓取和循环元标签

javascript - 数组中的随机图像显示图像标签错误

ios - 通过导航 Controller 继续

swift - Xcode 6.1 标题文本属性

python - 创建list of list时根据Index弹出元素+弹出的item

go - 仅通过 golang 中的第一个元素拆分字符串

java - RecyclerView 不显示任何内容

ios - 从顶部而不是固有大小的中心开始动画

python - 如何根据变量选择数据框中的列范围?