當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
数组中的reverse_数组reverse()方法以及JavaScript中的示例
生活随笔
收集整理的這篇文章主要介紹了
数组中的reverse_数组reverse()方法以及JavaScript中的示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數組中的reverse
JavaScript reverse()方法 (JavaScript reverse() method)
reverse() method is used to reverse the order of the elements in an array, it changes the actual array and also returns an array with reversed elements.
reverse()方法用于反轉數組中元素的順序,它更改實際數組并返回包含反轉元素的數組。
Syntax:
句法:
array_name.reverse();Parameters: None
參數:無
Return value: Array with reversed elements.
返回值:具有反向元素的數組。
Example:
例:
Input:var arr1 = [10, 20, 30, 40, 50];Function call:arr1.reverse();Output:50,40,30,20,10JavaScript Code to demonstrate example of Array.reverse() method
JavaScript代碼演示Array.reverse()方法的示例
<html> <head> <title>JavaScipt Example</title> </head><body><script>var arr1 = [10, 20, 30, 40, 50];var arr2 = ["Amit", "Ankur", "Akash"];//printing arrays before the reversing elementsdocument.write("arr1: " + arr1 + "<br>");document.write("arr1 length: " + arr1.length + "<br>");document.write("arr2: " + arr2 + "<br>");document.write("arr2 length: " + arr2.length + "<br>");//reversing arraysarr1.reverse();arr2.reverse();//printingdocument.write("<br>After reversing ...<br><br>");document.write("arr1: " + arr1 + "<br>");document.write("arr2: " + arr2 + "<br>");</script> </body> </html>Output
輸出量
arr1: 10,20,30,40,50 arr1 length: 5 arr2: Amit,Ankur,Akash arr2 length: 3After reversing ...arr1: 50,40,30,20,10 arr2: Akash,Ankur,Amit翻譯自: https://www.includehelp.com/code-snippets/array-reverse-method-with-example-in-javascript.aspx
數組中的reverse
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的数组中的reverse_数组reverse()方法以及JavaScript中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 保姆级教程,终于搞懂脏读、幻读和不可重复
- 下一篇: 解放双手!推荐一款阿里开源的低代码工具,