Home > Web Front-end > JS Tutorial > How to use reverse function

How to use reverse function

不言
Release: 2019-02-15 16:06:59
Original
15749 people have browsed it

The reverse function in How to use reverse function is used to reverse the order of elements in an array. The first element of the array will become the last element, otherwise the last element will become the first element. Let's take a look at the reverse function. specific usage.

How to use reverse function

Let’s first take a look at the basic syntax of the reverse() function

arr.reverse()
Copy after login

This function does not take any parameters.

Let’s look at the specific example of reverse function

The code is as follows

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
</head>
<body>
<script> 
  
function func() { 
  
    var arr = [34, 234, 567, 4]; 
    document.write(arr); 
  
    var new_arr = arr.reverse(); 
    document.write("<br>"); 
    document.write(new_arr); 
} 
func(); 
</script> 
</body>
</html>
Copy after login

The running result is as follows: the array elements are reversed.

34,234,567,4
4,567,234,34
Copy after login

This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use reverse function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template