We can create an empty array by specifying the Element type of your array in the declaration.
For example:
var numbers: [Double] = []
var names: [String] = []
// The full type name is also allowed
var emptyFloats: Array<Float> = Array()
Add value to the array:
names.append("James")
Also, we can just append a variable. For example,
let myName = "Yogesh"
names.append(myName)
Add multiple elements at the same time by passing another array or a sequence of any kind to the append(contentsOf:) method.
names.append(contentsOf: ["Shakia", "William"])
You can add new elements in the middle of an array by using the insert(_:at:) method for single elements and by using insert(contentsOf:at:) to insert multiple elements from another collection or array literal. The elements at that index and later indices are shifted back to make room.
names.insert("Liam", at: 3)
To remove elements from an array, use the remove(at:), removeSubrange(_:), and removeLast() methods.
names.remove(at: 0)
names.removeLast()
array empty