JavaScript TypedArray reverse() Method - JavaScript Tutorial

JavaScript TypedArray reverse() Method

BLUF: This tutorial on JavaScript TypedArray reverse() Method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript TypedArray reverse() Method

Understanding JavaScript TypedArray reverse() Method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The reverse method in JavaScript serves the purpose of reversing the order of elements in an array. This means that the initial element of the array will become the final element, while the final element will turn into the first element.

Syntax:

Example

Array.reverse()

Parameters:

No Parameters.

Return value:

Return the reversed original array.

Browser Support:

Chrome 1.0
Safari Yes
Firefox 1.0
Opera Yes

Example 1

JavaScript reverse Method

Example

<script>

// JavaScript to illustrate reverse() method

function pyVisualizer() {

     //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

}

runExample();

</script>

Output:

Output

4,5,2,1

Example 2

JavaScript reverse Method

Example

<script>

// JavaScript to illustrate reverse() method

function pyVisualizer() {

    //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

}

runExample();

</script>

Output:

Output

RDBMS,C++,C,Java

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience