• How to Reverse a JavaScript Array

    You can use the native reverse() function to reverse an array in JavaScript.

    Here is the sample code.

    var list = [1, 2, 3, 4, 5];
    list.reverse();
    // 5,4,3,2,1

    You can store the array in a separate variable using the slice() operator.

    var list = [1, 2, 3, 4, 5];
    var reversedList = list.slice().reverse();
    console.log(list);
    // 1,2,3,4,5
    console.log(reversedList);
    // 5,4,3,2,1