js中数组的pop方法_数组pop()方法以及JavaScript中的示例

编程知识 行业动态 更新时间:2024-06-13 00:17:48

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中的示例

本文发布于:2023-03-25 19:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/8ca3d8e08db9d52744ca381206c633e8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   方法   示例   js   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!