The reverse function in How to use reverse function is used to reverse the order of elements in an array. The first element of the array will become the last element, otherwise the last element will become the first element. Let's take a look at the reverse function. specific usage.
Let’s first take a look at the basic syntax of the reverse() function
arr.reverse()
This function does not take any parameters.
Let’s look at the specific example of reverse function
The code is as follows
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script> function func() { var arr = [34, 234, 567, 4]; document.write(arr); var new_arr = arr.reverse(); document.write("<br>"); document.write(new_arr); } func(); </script> </body> </html>
The running result is as follows: the array elements are reversed.
34,234,567,4 4,567,234,34
This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !
The above is the detailed content of How to use reverse function. For more information, please follow other related articles on the PHP Chinese website!