.reverse() method reverses an array in place, mutating the original array, and returns the elements within it so that the first element becomes the last element and vice versa.
var topBabyNames = ["Jackson", "Liam", "Noah", "Olivia", "Riley", "Sophia"]topBabyNames.reverse()print(topBabyNames)// Output: ["Sophia", "Riley", "Olivia", "Noah", "Liam", "Jackson"]
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn Swift on Codecademy
Build iOS Apps with SwiftUIBy the end of this Skill Path, you will have created your very own fully functional quiz game for iOS devices—and learned Swift too!
Includes 7 Courses