본문 바로가기
프로그래밍

자바스크립트 객체(object)

by Youngbin Kwon 2020. 7. 30.

자바스크립트 객체 (object)

객체

객체란 여러 속성을 하나의 변수에 저장할 수 있는 데이터 타입이며, key:value 구조로 정의할 수 있다.

 

객체의 생성 (예시)

let jisungPark = {'height': 178, 'team': 'Manchester United', 'country': 'Korea'};

 

let jisungPark = {};
jisungPark['height'] = 178;
jisungPark['team'] = 'Manchester United';
jisungPark['country'] = 'Korea';

 

var jisungPark = new Object();
jisungPark['height'] = 178;
jisungPark['team'] = 'Manchester United';
jisungPark['country'] = 'Korea';

 

객체 값 접근

console.log(jisungPark['height']);
//output = 178

 

console.log(jisungPark.height);
//output = 178

 

객체 내 데이터의 반복작업

for [변수명] in [객체명]

for(key in jisungPark) {
    document.write("key : "+key+" value : "+jisungPark[key]+"<br />");
}

//output
key : height value : 178
key : team value : Manchester United
key : country value : Korea

'프로그래밍' 카테고리의 다른 글

wecode 사전스터디(8/2) 로그  (0) 2020.08.02
wecode 사전스터디(7/31) 로그  (0) 2020.08.01
wecode 사전스터디(7/29) 로그  (0) 2020.07.29
wecode 사전스터디(7/28) 로그  (0) 2020.07.28
github 관련 링크들  (0) 2020.07.28

댓글