-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex01.html
More file actions
31 lines (30 loc) · 912 Bytes
/
ex01.html
File metadata and controls
31 lines (30 loc) · 912 Bytes
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
<html>
<title>
객체
</title>
<head>
<script>
var grades = {'fir':10, 'sec':20, 'thr':30}
</script>
</head>
<body>
<ul>
<script>
document.write(grades['fir'] + '<br>')
document.write(grades['se'+'c'],'<br>')
document.write(grades.thr,'<br>')
</script>
객체란 값을 담는 그릇, 배열과 비슷하다. <br>객체안의 데이터는 key와 value로 이뤄져 있으며, 자바의 Map과 유사<br>
<br>반복문으로 객체 다루기<br> for(key in Obejct) -> 향상된 for문과 비슷하다.<br><br>
<script>
for(key in grades){
//document.write(key + "<br />");
//document.write(value + "<br />");
document.write("<li>key: " +key+ ", value: " +grades[key] + "</li>");
}
</script>
</ul>
key -> key값 리턴<br>
[key] -> 해당 key값의 value 리턴
</body>
</html>