Array.reverse Last updated: 22. Jul 2024
The reverse() method reverses an array in place and returns the reference to the same array.
Parameters
This function takes no parameters
Returns
Returns the array in reverse order. (Also changes the same array)
Example
Code example (#JS)
#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.#{
// Init an array with three items
var arr = ["one", "two", "three"];
// Reverse the order of the items
arr.reverse();
// Output the array to screen, now reversed
write(JSON.stringify(arr));
}#
Output
The #JS code above produces the output shown below:["three","two","one"]