배열에 요소를 추가하거나 삭제할 때 사용되는 메서드이다. push()는 배열 끝에 하나 이상의 요소를 추가하는데 사용한다. 추가된 요소를 포함한 배열의 크기를 할당한다. 반면 pop()은 배열 끝 요소를 제거 또는 호출함
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let array1 = ["apple","pear","orange"];
let popvar = array1.pop();
document.write(popvar + " + array1 +" + "<br>");
array1.push(false, "another");
document.write(array1.length + ", " + array1 + "<br>");
</script>
</body>
</html>
'웹 프로그래밍 기초 > 객체' 카테고리의 다른 글
shift(), unshift() (0) | 2025.04.07 |
---|---|
indexOf() (0) | 2025.04.07 |
concat()메서드 (0) | 2025.04.07 |
toString(), join() (0) | 2025.04.07 |
내장 객체 (Array) (0) | 2025.04.07 |