Swift-数组遍历+合并

遍历

  let array : [String] = ["111","222","333"]

一:获取下标值

        for index in 0..

结果:
0
1
2

二:获取元素

        for item in array {
            print("item")
        }

结果:
111
222
333

三:获取下标+元素

        for (index, item) in array.enumerated() {
            print("index,item")
        }

结果:
0,111
1,222
2,333

合并

注意:
相同元素类型的数组才能合并,不同元素类型的不能相加合并。

        let array1 = ["111","222","333"]
        let array2 = ["444","555","666"]
        let array3 = array1 + array2
        print(array3)

结果:
["111", "222", "333", "444", "555", "666"]

你可能感兴趣的:(Swift-数组遍历+合并)