Javascript Data Type How to - Reverse an array








Question

We would like to know how to reverse an array.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from w w w. jav  a2s  .  co m-->
var array = [0, 1, 2];
document.writeln(array.reverse().join(','));

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: