-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx29_Array.html
More file actions
43 lines (38 loc) · 1.36 KB
/
Ex29_Array.html
File metadata and controls
43 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<html>
<head>
<meta charset="utf-8" />
<title>Array(정적 + 동적)</title>
<script>
// Java : 정적(배열 크기 고정)
// Java : Collection(동적)
var array = ["포도", "사과"];
document.write(array.toString() + "<br>");
for (var i = 0; i < array.length; i++) {
document.write(array[i] + "<br />");
}
// array[0] = 포도, array[1] = 사과
array[2] = "바나나"; // 동적 데이터 추가 가능
document.write(`${array} / ${array.length}<br>`);
array[10] = "애플망고";
document.write(`${array} / ${array.length}<br>`);
document.write(`${array[9]} / ${array.length}<br>`);
array[9] = "배";
document.write(`초기화 후 : ${array[9]} / ${array.length}<br>`);
var array2 = ["one", "two", "three"];
document.write(`${array2.length} <br>`);
array2.length = 2; // 강제로 줄였음
for (const index in array2) {
document.write(`${array2[index]}<br>`);
}
array2.length = 4;
document.write(array2 + "<br>");
// TODAY POINT
array2.push("four");
document.write("push: " + array2 + "<br>");
document.write("push: " + array2.length + "<br>");
document.write("pop: " + array2.pop() + "<br>");
document.write("pop: " + array2.pop() + "<br>");
</script>
</head>
<body></body>
</html>