.reverse()
Published Oct 11, 2022
Contribute to Docs
The .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.
Syntax
arrayName.reverse()
Example
var topBabyNames = ["Jackson", "Liam", "Noah", "Olivia", "Riley", "Sophia"]topBabyNames.reverse()print(topBabyNames)// Output: ["Sophia", "Riley", "Olivia", "Noah", "Liam", "Jackson"]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Swift on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours