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()方法用于从数组末尾删除元素,它会更改数组的长度。
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 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
翻译自: https://www.includehelp/code-snippets/array-pop-method-with-example-in-javascript.aspx
js中数组的pop方法
更多推荐
js中数组的pop方法_数组pop()方法以及JavaScript中的示例
发布评论