In Swift, we use the removeLast()
method to remove the last element of an array.
arr.removeLast()
This method takes no parameters.
It returns the array arr
but with its last element removed.
// create an arrayvar gnaam = ["Google", "Netflix", "Amazon", "Apple", "Facebook"]print("Initial array is ", gnaam)// remove last elementgnaam.removeLast()print("Last Element Removed: ", gnaam)// add new elementgnaam.append("Meta")// print new array valuesfor coy in gnaam{print(coy)}
gnaam
. It contains the names of the big tech companies.removeLast()
method on the array."Facebook"
, was removed.Meta
to the array.for-in
loop to print each element of the array.