[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/pop [Back]  [Original]

Array.prototype.pop() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype.pop()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

pop() Array , . .

In this article

const plants = ["broccoli", "cauliflower", "cabbage", "kale", "tomato"];

console.log(plants.pop());
// Expected output: "tomato"

console.log(plants);
// Expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]

plants.pop();

console.log(plants);
// Expected output: Array ["broccoli", "cauliflower", "cabbage"]

js
pop()

.

. undefined .

pop() . pop() undefined .

Array.prototype.shift() pop() .

pop() . this . this arr.slice(0, -1) .

pop() . this length . , .

4 myFish .

js
const myFish = ["angel", "clown", "mandarin", "sturgeon"];

const popped = myFish.pop();

console.log(myFish); // ['angel', 'clown', 'mandarin' ]

console.log(popped); // 'sturgeon'

pop()

pop() this length . 0 length 0 ( undefined ). length - 1 .

js
const arrayLike = {
  length: 3,
  unrelated: "foo",
  2: 4,
};
console.log(Array.prototype.pop.call(arrayLike));
// 4
console.log(arrayLike);
// { length: 2, unrelated: 'foo' }

const plainObj = {};
// length  , length 0
Array.prototype.pop.call(plainObj);
console.log(plainObj);
// { length: 0 }

push pop , .

. , Array.prototype.push Array.prototype.pop call .

js
const collection = {
  length: 0,
  addElements(...elements) {
    // obj.length   
    //  .

    // push  
    //     .
    return [].push.call(this, ...elements);
  },
  removeElement() {
    // obj.length   
    //  .

    // pop  
    //   .
    return [].pop.call(this);
  },
};

collection.addElements(10, 20, 30);
console.log(collection.length); // 3
collection.removeElement();
console.log(collection.length); // 2

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.pop


Web Proxy Viewer  |  New URL  |  Original Page