배열의 마지막에 데이터를 추가하고 싶다면
push() 를 통해 배열에 데이터가 추가됩니다.
- push를 사용하여 배열에 cd, ef 라는 값을 추가해 보자.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Array</h1>
<h2>Syntax</h2>
<script>
let boom = ["A", "B"];
boom.push('cd');
boom.push('ef');
</script>
<h2>get</h2>
<script>
document.write(boom[0]); //A
document.write(boom[1]); //B
document.write(boom[2]); //cd
document.write(boom[3]); //ef
</script>
<h2>add</h2>
<script>
</script>
<h2>count</h2>
<script>
document.write(boom.length); //4
</script>
</body>
</html>
'Javascript > 기초' 카테고리의 다른 글
[조건문] if문이란? (0) | 2023.11.29 |
---|---|
[자료와 변수] - 자료형 (0) | 2023.11.28 |
배열에서 데이터 꺼내기 (1) | 2023.11.26 |
[Programmers/JavaScript] Lv.0 - a 와 b 출력하기 (1) | 2023.11.18 |
[calendar]자바스크립트로 날짜를 구할 수 있을까? (0) | 2023.11.14 |