js中数组的pop⽅法_数组pop()⽅法以及JavaScript中的⽰
js中数组的pop⽅法
JavaScript pop()⽅法 (JavaScript pop() method)
pop() method is used remove an element from the end of an array, it changes the length of the array.
pop() method
pop()⽅法⽤于从数组末尾删除元素,它会更改数组的长度。
pop()⽅法
Syntax:
句法:
array_name.pop();
Examples:
例⼦:
Input:
var countries = ["INDIA", "USA", "UK", "CANADA", "RUSSIA"];
Function call:
countries.pop();
countries.pop();
countries.pop();
Output:
"INDIA", "USA"
javascript全局数组JavaScript Code to demonstrate example of Array.pop() method
JavaScript代码演⽰Array.pop()⽅法的⽰例
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var countries = ["INDIA", "USA", "UK", "CANADA", "RUSSIA"];  document.write("countries: " + countries + "<br>");
document.write("length is: " + countries.length + "<br>");
//removing elements
countries.pop();
countries.pop();
countries.pop();
document.write("countries: " + countries + "<br>");
document.write("length is: " + countries.length + "<br>");
</script>
</body>
</html>
Output
输出量
countries: INDIA,USA,UK,CANADA,RUSSIA
length is: 5
countries: INDIA,USA
length is: 2
js中数组的pop⽅法