.reverse()
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"]