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

Array.prototype.pop() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Array.prototype.pop()

Baseline

20157

pop()

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

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

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

plants.pop();

console.log(plants);
// : 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  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 
    // length 
    return [].push.call(this, ...elements);
  },
  removeElement() {
    // obj.length 
    // 

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

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

ECMAScript 2027 LanguageSpecification
# sec-array.prototype.pop


Web Proxy Viewer  |  New URL  |  Original Page