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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html>
 <head>
  <title>Array 객체 다루기</title>
  <style type="text/css">
   input {
    width:150px;
   }
  </style>
  <script language="javascript">
   var objArray = new Array();
   
   function printArray() {
    var objResult = document.getElementById("result");
    var objItem = document.getElementById("item");
    objResult.innerText = objArray.join(",");
    
    objItem.value= "";
    objItem.focus();
   }
   
   function doPush() {
    var objItem = document.getElementById("item");
    objArray.push(objItem.value);
    
    printArray();
   }
   
   function doShift() {
    var objValue = objArray.shift();
    printArray();
    alert("꺼내온 값은 " + objValue + "입니다.");
   }
   
   function doPop() {
    var objValue = objArray.pop();
    printArray();
    alert("꺼내온 값은 " + objValue + "입니다.");
   }
   
   function doReverse() {
    objArray = objArray.reverse();
    printArray();
   }
   
   function doSort() {
    objArray = objArray.sort(function(a, b){ return a-b; });
    printArray();
   }
  </script>
 </head>
 <body>
  <input type="text" id="item">
  <input type="button" value="배열에 추가하기"
  onclick="doPush()"><br>
  현재 배열의 값:
  <span id="result"></span><br><br>
  <input type="button" value="Shift로 꺼내기"
  onclick="doShift()">
  <input type="button" value="Pop으로 꺼내기"
  onclick="doPop()"><br>
  <input type="button" value="Reverse로 뒤집기"
  onclick="doReverse()">
  <input type="button" value="Sort로 정렬하기"
  onclick="doSort()">
 </body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
 

'HTML & CSS & JAVASCRIPT' 카테고리의 다른 글

쿠키와 세션  (0) 2019.06.20
예제_회원가입  (0) 2019.06.20
예제_input type 활용  (0) 2019.06.20
예제_계산기  (0) 2019.06.20
JAVASCRIPT 예제_prompt, confirm  (0) 2019.06.20

+ Recent posts