| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/pop | [Back] [Original] |
Get to know MDN better
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"]
pop()
pop() pop() undefined
Array.prototype.shift() pop()
pop() this this arr.slice(0, -1)
4 myFish
const myFish = ["angel", "clown", "mandarin", "sturgeon"];
const popped = myFish.pop();
console.log(myFish); // ['angel', 'clown', 'mandarin' ]
console.log(popped); // 'sturgeon'
pop() this length 0 length 0 undefined length - 1
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
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 |
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |