The removeFirst()
method of an array in Swift removes and returns the first element of an array.
arr.removeFirst()
This method takes no parameters.
The removed element is returned.
// create arraysvar numbers = [1, 3, 10, 4]var techCoys = ["Google", "Amazon", "Netflix"]var letters = ["a", "b", "c", "d", "e"]var fruits = ["apple", "mango"]// remove first elementslet num = numbers.removeFirst()let tech = techCoys.removeFirst()let letter = letters.removeFirst()let fruit = fruits.removeFirst()// print resultsprint(num)print(tech)print(letter)print(fruit)// print arrays againprint("New Arrays: \n")print(numbers)print(techCoys)print(letters)print(fruits)
removeFirst()
method to remove the first elements of the arrays that we’ve created. We then store the results in some variables.removeFirst()
method.