Baseline Widely available
pop()
ë©ìëë Array
ì¸ì¤í´ì¤ì ë©ìëë¡, ë°°ì´ìì ë§ì§ë§ ìì를 ì ê±°íê³ ê·¸ ìì를 ë°íí©ëë¤. ì´ ë©ìëë ë°°ì´ì 길ì´ë¥¼ ë³ê²½í©ëë¤.
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"]
구문 매ê°ë³ì
ìì.
ë°í ê°ë°°ì´ìì ì ê±°í ìì. ë¹ ë°°ì´ì ê²½ì° undefined
를 ë°íí©ëë¤.
pop()
ë©ìëë ë°°ì´ìì ë§ì§ë§ ìì를 ì ê±°íê³ ê·¸ ê°ì í¸ì¶ììê² ë°íí©ëë¤. ë¹ ë°°ì´ìì pop()
ì í¸ì¶íë©´ undefined
를 ë°íí©ëë¤.
Array.prototype.shift()
ë pop()
ê³¼ ì ì¬í ëìì íì§ë§ ë°°ì´ì 첫 ë²ì§¸ ììì ì ì©ë©ëë¤.
pop()
ë©ìëë ë°°ì´ì ë³ê²½ìí¤ë ë©ìëì
ëë¤. this
ì 길ì´ì ë´ì©ì ë³ê²½í©ëë¤. this
ì ê°ì ê·¸ëë¡ ì ì§íë©´ì ë§ì§ë§ ììê° ì ê±°ë ì ë°°ì´ì ë°ííê³ ì¶ë¤ë©´ ëì arr.slice(0, -1)
ì ì¬ì©í ì ììµëë¤.
pop()
ë©ìëë ë²ì© ë©ìëì
ëë¤. this
ê°ì´ length
ìì±ê³¼ ì ì í¤ ìì±ë§ ìì¼ë©´ ë©ëë¤. 문ìì´ë ë°°ì´ê³¼ ì ì¬íì§ë§, 문ìì´ì ë¶ë³ì´ê¸° ë문ì ì´ ë©ìë를 문ìì´ì ì ì©íë ê²ì ì ì íì§ ììµëë¤.
ë¤ì ì½ëë 4ê°ì ììê° ìë myFish
ë°°ì´ì ìì±íê³ ë§ì§ë§ ìì를 ì ê±°í©ëë¤.
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
ìì¹ì ìì±ì´ ë°íëê³ ìì ë©ëë¤.
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
ì ì¬ì©íì¬ ë§ì¹ ë°°ì´ì ë¤ë£¨ë ê²ì²ë¼ ìì
ëë¤.
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
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4