Changing the order of elements of an array by reverse() function
<script>
var array_no=[1,2,3,4] // Original array
array_no.reverse() // reversed
document.write(array_no.join(",")) // display elements
</script>
Output is here
4,3,2,1
We can reverse the order of the element by using the reverse method. Here the first element will became last method and last element became first and other elements will also change their positions.
We have created an array of scripts and then displayed the elements. Then we have applied the command scripts.reverse(); to our scripts array and displayed again all the elements to see the result of reverse() function.