• 키를 기반으로 데이터를 저장해야 할 때
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title> 
    <script src="main.js"></script>
</head>
<body>
    <script>
        var exam = new Object();
        exam.kor = 30;
        exam.eng = 59;
        exam,math = 50;

        alert(exam.kor + exam.eng);
    
    </script>
</body>
</html>

89가 출력이된다.

  • 키를 이용한 데이터 관리 : Map

var exam = new Object();

exam[“kor”] = 30; exam[“eng”] = 59; exam[“math”] = 50;

aler(exam[“kor”]); -> exam 이 가지고있는 속성을 변수로 꺼내야할때는 위의방식으로밖에쓸수없다.

댓글남기기