Search

_0004_배열_추가_맨뒤에_push

대분류
STEP00 기초문법
소분류
기초문법_배열

영상

개념

<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>배열 추가 - push()</title> </head> <body> <script> /* [개념] 배열 맨뒤에 요소 추가 (1) push() (2) 배열의 제일 끝에 새로운 요소를 추가한다. (3) 추가하면 배열의 길이는(length)는 증가한다. (4) 변경된 배열의 길이를 반환한다. */ let arr = ["미금", "정자", "수서"]; // 방법1) push() 메서드 이용해 추가 arr.push("양재"); // document.write(arr.push("양재") + "<br>"); // 4 document.write(arr + "<br>"); // 미금,정자,수서,양재 // 방법2) 인덱스를 지정하여 추가 arr[arr.length] = "당곡"; document.write(arr + "<br>"); // 미금,정자,수서,양재,당곡 </script> </body> </html>
Java
복사