C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript TypedArray reverse() MethodThe JavaScript reverse() method is used to reverse the array. The first element of the array becomes the last element of the array and vice versa. Syntax:Array.reverse() Parameters:No Parameters. Return value:Return the reversed original array. Browser Support:
Example 1JavaScript reverse() Method <script> // JavaScript to illustrate reverse() method function JavaTpoint() { //Original Array var arr = [1, 2, 5, 4]; document.write(arr); //Reversed array var new_arr = arr.reverse(); document.write("<br>"); document.write("output using reverse() method </br>"); document.write(new_arr); // expected output: 4,5,2,1 } JavaTpoint(); </script> Output: 4,5,2,1 Example 2JavaScript reverse() Method <script> // JavaScript to illustrate reverse() method function JavaTpoint() { //Original Array var arr = ['Java','C','C++','RDBMS' ]; document.write(arr); //Reversed array var new_arr = arr.reverse(); document.write("<br>"); document.write("output using reverse() method </br>"); document.write(new_arr); // expected output: RDBMS,C++,C,Java } JavaTpoint(); </script> Output: RDBMS,C++,C,Java
Next TopicJavaScript TypedArray Object
|