javascript
数组shift方法_数组shift()方法以及JavaScript中的示例
數組shift方法
JavaScript shift()方法 (JavaScript shift() method)
shift() method is used to remove the first element of an array and returns the deleted element.
shift()方法用于刪除數組的第一個元素,并返回刪除的元素。
It changes the array length.
它改變了數組的長度。
Syntax:
句法:
array_name.shift();Parameters: None
參數:無
Return value: It returns a type of value that array contains, it actual returns deleted the element.
返回值:它返回數組包含的一種類型的值,它實際返回已刪除的元素。
Example:
例:
Input:var arr1 = [10, 20, 30, 40, 50];Function call:arr1.shift();Output:20, 30, 40, 50JavaScript Code to demonstrate example of Array.shift() method
JavaScript代碼演示Array.shift()方法的示例
<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 deleting elementsdocument.write("arr1: " + arr1 + "<br>");document.write("arr1 length: " + arr1.length + "<br>");document.write("arr2: " + arr2 + "<br>");document.write("arr2 length: " + arr2.length + "<br>");//removing elementarr1.shift();arr1.shift(); arr2.shift(); document.write("<br>After removing...<br><br>");document.write("arr1: " + arr1 + "<br>");document.write("arr1 length: " + arr1.length + "<br>");document.write("arr2: " + arr2 + "<br>");document.write("arr2 length: " + arr2.length + "<br>"); </script> </body> </html>Output
輸出量
arr1: 10,20,30,40,50 arr1 length: 5 arr2: Amit,Ankur,Akash arr2 length: 3After removing...arr1: 30,40,50 arr1 length: 3 arr2: Ankur,Akash arr2 length: 2翻譯自: https://www.includehelp.com/code-snippets/array-shift-method-with-example-in-javascript.aspx
數組shift方法
總結
以上是生活随笔為你收集整理的数组shift方法_数组shift()方法以及JavaScript中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mts模式_MTS的完整形式是什么?
- 下一篇: getdate 日期间隔_日期getDa