Home  >  Article  >  Web Front-end  >  How to use reverse function

How to use reverse function

不言
不言Original
2019-02-15 16:06:5915727browse

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

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>

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

34,234,567,4
4,567,234,34

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!

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
Previous article:How to use some functionNext article:How to use some function