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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
 
    <!-- ex06.htm -->
    
    
    
    <script type="text/javascript">
    
    
        //문자열
        var txt = "hello~ hong~";
        
        //길이
        console.log(txt.length); //12
        
        //검색(indexOf, lastIndexOf)
        console.log(txt.indexOf("hong")); //7
        console.log(txt.indexOf("h")); //0
        console.log(txt.indexOf("h")); //0
        console.log(txt.indexOf("h"1)); //7
        
        //치환(1회용)
        console.log(txt.replace("hong""test"));
        console.log(txt.replace("h""t")); //tello~ hong~, 첫h만 바뀜
        
        //대소문자 변환
        console.log(txt.toUpperCase());
        console.log(txt.toLowerCase());
        
        //분할
        var names ="홍길동,아무게,하하하";
        var result = names.split(",");//반환값 배열(String[])
        console.log(result[0]); //홍
        console.log(result[1]); //아
        console.log(result[2]); //하
        
        //추출
        console.log(txt.charAt(0)); //0번째의 문자 가져와라 -> h
        console.log(txt.charCodeAt(0)); //0번째의 문자 코드 -> 104
        console.log(txt.substring(04)); //hell
        console.log(txt.substring(5)); //~ hong~
        
        //이스케이프 시퀀스
        // \n  \r  \t  \b  \"  \'  \\
        
        //제어문
        if (true) {
            console.log("참")
        } else {
            console.log("거짓");
        }
        
        
        var n = 10;
        switch    (n) {
            case 10:
                console.log("십")
                break;
            case 20:
                console.log("이십")
                break;
            default:
                console.log("몰라");
                break;
                
        }    
        
        
        for (var i=0; i<10; i++) {
            console.log(i);
        }
        
        
        while (true) {
            
        }
        
            
        
    </script>    
 
 
</body>
</html>
cs


'WEB > JS' 카테고리의 다른 글

BOM / DOM 방식  (0) 2016.01.22
날짜시간 / 배열(array)  (0) 2016.01.22
함수  (0) 2016.01.22
기본 문법 var  (0) 2016.01.22
출력하기 - alert(); / html element / console.log();  (0) 2016.01.22

+ Recent posts