insert 插入
var myArray = ["Steve", "Bill", "Linus", "Bret"]
myArray.insert("jaywcjlove", at: 1)
print(myArray)
// ["Steve", "jaywcjlove", "Bill", "Linus", "Bret"]
append 添加到末尾
var myArray = ["Steve", "Bill", "Linus", "Bret"]
myArray.append("wcj")
print(myArray)
// ["Steve", "Bill", "Linus", "Bret", "wcj"]
合并数组
var array1 = [1,2,3,4,5]
let array2 = [6,7,8,9]
let array3 = array1+array2
print(array3)
array1.append(contentsOf: array2)
print(array1)
数组过滤
let words = ["hello", "world", "this", "is", "a", "list", "of", "strings"]
let filtered = words.filter { word in
return word.count >= 3
}
print(filtered)
// ["hello", "world", "this", "list", "strings"]
let words = ["hello", "world", "this", "is", "a", "list", "of", "strings"]
let filtered = words.filter{ $0.contains("is") }
print(filtered)
// ["this", "is", "list"]