Home >Web Front-end >JS Tutorial >How to reverse an array in JavaScript

How to reverse an array in JavaScript

青灯夜游
青灯夜游Original
2021-06-17 18:05:1127070browse

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()".

How to reverse an array in JavaScript

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:

How to reverse an array in JavaScript

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn