const arr = [1, 2, 3];

// 배열의 마지막 끝의 요소를 제거합니다.
arr.pop();
console.log(arr); // 출력: [1, 2]
arr.pop()
const arr = [1, 2, 3];

// 배열의 마지막 끝의 요소를 제거합니다.
const removedItem = arr.pop();
console.log(arr); // 출력: [1, 2]
console.log("반환 값 -", removedItem); // 출력: "반환 값 - 3"

// 배열이 비어있을 경우 1
const emptyArray_1 = [];
const emptyArray_1_removedItem = emptyArray_1.pop(); // // 제거할 마지막 요소 값이 없이 배열이 비어 있음

console.log("반환 값 -", emptyArray_1_removedItem); // 출력: "반환 값 -" undefined

// 배열이 비어있을 경우 2
const emptyArray_2 = [1];
const emptyArray_2_removedItem = emptyArray_2.pop();

console.log("반환 값 -", emptyArray_2_removedItem); // 출력: "반환 값 - 1"
const fruits = ["apple", "banana", "cherry"];
const removedFruit = fruits.pop();

console.log(removedFruit); // 출력: "cherry"
const fruits = ["apple", "banana", "cherry"];
fruits.pop();

console.log(fruits.length); // 출력: 2
const fruits = ["apple", "banana", "cherry"];

// 역순으로 정렬하기 위한 빈 배열 생성
const reversedFruits = [];

// 역순으로 출력하기 위해 반복문 사용
while (fruits.length > 0) {
  reversedFruits.push(fruits.pop());
}

// 역순으로 정렬된 배열 출력
console.log(reversedFruits); // 출력: ["cherry", "banana", "apple"]
const fruits = ["apple", "banana", "cherry"];

// 배열을 역순으로 정렬
$reversedFruits = fruits.reverse();

// 역순으로 정렬된 배열 출력
console.log($reversedFruits);

// 역순으로 정렬된 배열 출력
console.log(reversedFruits); // 출력: ["cherry", "banana", "apple"]
const fruits = ["apple", "banana", "cherry"];

// 배열의 마지막 요소를 제거
delete fruits[fruits.length - 1];

// 배열 출력
console.log(fruits); // 출력: ["cherry", "banana", 비어 있음]
console.log(fruits[3]); // 출력: undefined
pop() 함수에 대한 브라우저 호환성
메서드
데스크탑 Chrome
Chrome
데스크탑데스크탑 Edge
Edge
데스크탑 Firefox
Firefox
Safari
Safari
pop() 1 12 1 1

caniuse.com에서 더 자세한 정보를 확인해 보세요.