Swift Array instance method drop(at: Int)
问题 Array in Swift has several instance methods for excluding elements, such as dropFirst(), dropLast(), drop(while:), etc. What about drop(at:) ? Note: I'd use remove(at:), but the array I'm working with is a let constant. 回答1: Note: I'd use remove(at:) , but the array I'm working with is a constant. I wouldn't let that stop you: 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