Home > Web Front-end > JS Tutorial > javascript pop() 删除数组中最后的一个元素

javascript pop() 删除数组中最后的一个元素

WBOY
Release: 2016-06-01 09:54:26
Original
1602 people have browsed it

pop() 方法删除一个数组中的最后的一个元素,并且返回这个元素。

pop()基本语法:

<code class="language-javascript">array.pop()</code>
Copy after login

 

pop()方法说明

pop 方法删除一个数组中的最后一个元素,并且把这个删除掉的元素返回给调用者。

pop 被有意设计成具有通用性,该方法可以通过 call 或 apply 方法应用于一个类数组(array-like)对象上。

 

pop()方法实例:

下面的代码首先创建了一个拥有四个元素的数组 myFish,然后删除掉它的最后一个元素。

<code class="language-javascript">var myFish = ["angel", "clown", "mandarin", "surgeon"];

console.log("myFish before: " + myFish);

var popped = myFish.pop();

console.log("myFish after: " + myFish);
console.log("Removed this element: " + popped);</code>
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template