How to append multiple elements to array in Swift

2 Answers

0 votes
var arr: [Any] = [3.14, "swift", 123.874, 98.999, "java", "c"]

arr.append(contentsOf: ["c++", "python", 6437.01])

print(arr) 

for element in arr {
    print(element)
}


 
 
 
/*
run:
 
[3.14, "swift", 123.874, 98.999, "java", "c", "c++", "python", 6437.01]
3.14
swift
123.874
98.999
java
c
c++
python
6437.01

*/

 



answered Jun 15, 2023 by avibootz
0 votes
var arr: [Any] = [3.14, "swift", 123.874, 98.999, "java", "c"]

arr += ["c++", "python", 6437.01]

print(arr) 

for element in arr {
    print(element)
}


 
 
 
/*
run:
 
[3.14, "swift", 123.874, 98.999, "java", "c", "c++", "python", 6437.01]
3.14
swift
123.874
98.999
java
c
c++
python
6437.01

*/

 



answered Jun 15, 2023 by avibootz

Related questions

1 answer 142 views
1 answer 146 views
146 views asked Jun 15, 2023 by avibootz
1 answer 139 views
1 answer 193 views
1 answer 184 views
1 answer 81 views
1 answer 167 views
...