Home >Web Front-end >JS Tutorial >How to reverse an array in JavaScript
In JavaScript, you can use the reverse() function to reverse the order of the array. This function can reverse the order of the elements in the array and return the current array in reverse order. The syntax format is "array.reverse()".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
reverse() method is used to reverse the order of elements in the array and can return the current array in reverse sorted form.
Syntax
array.reverse()
Return value: the array in reverse order
Example: reverse the array
var arr = [1,2,3,4,5,6]; console.log(arr.reverse());//返回:6,5,4,3,2,1
Output:
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to reverse an array in JavaScript. For more information, please follow other related articles on the PHP Chinese website!