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 array var gnaam = ["Google", "Netflix", "Amazon", "Apple", "Facebook"] print("Initial array is ", gnaam) // remove last element gnaam.removeLast() print("Last Element Removed: ", gnaam) // add new element gnaam.append("Meta") // print new array values for 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.RELATED TAGS
CONTRIBUTOR
View all Courses