Notice
Recent Posts
Recent Comments
Link
초짜코딩의 잡동사니
데이터 저장 : 객체2 본문

1. 객체 : 데이터를 저장(키와 값) : 표현방법5 : 배열 속의 객체
{
const obj = [
{a: 100, b: 200},
{c: "javascript"}
];
document.write(obj[0].a);
document.write(obj[0].b);
document.write(obj[1].c);
}
결과보기
100
200
javascript
200
javascript
2. 객체 : 데이터를 저장(키와 값) : 표현방법6 : 객체 속의 배열
{
const obj = {
a: 100,
b: [200,300],
c: {x: 400, y: 500,},
d: "javascript"
}
document.write(obj.a);
document.write(obj.b[0]);
document.write(obj.b[1]);
document.write(obj.c.x);
document.write(obj.c.y);
document.write(obj.d);
}
결과보기
100
200
300
400
500
javascript
200
300
400
500
javascript
3. 객체 : 데이터를 저장(키와 값) : 표현방법7 : 객체 속의 변수
{
const a = 100;
const b = 200;
const c = "javascript";
const obj = {a, b, c}
document.write(obj.a);
document.write(obj.b);
document.write(obj.c);
}
결과보기
100
200
javascript
200
javascript
4. 객체 : 데이터를 저장(키와 값) : 표현방법8 : 객체 속의 함수
{
const obj = {
a: 100,
b: [200, 300],
c: {x:400, y:500},
d: "javascrript",
e: function(){
document.write("javascript가 실행 되었습니다.");
},
f: function(){
document.write(obj.d + "가 실행되었습니다.");
},
g: function(){
document.write(this.d + "가 실행되었습니다.");
}
}
document.write(obj.a);
document.write(obj.b);
document.write(obj.b[0]);
document.write(obj.b[1]);
document.write(obj.c.x);
document.write(obj.c.y);
obj.e();
obj.f();
obj.g();
}
결과보기
100
200300
200
300
400
500
javascript가 실행되었습니다.
javascript가 실행되었습니다.
javascript가 실행되었습니다.
200300
200
300
400
500
javascript가 실행되었습니다.
javascript가 실행되었습니다.
javascript가 실행되었습니다.
'JavaScript' 카테고리의 다른 글
데이터 불러오기 : 배열 (0) | 2022.02.16 |
---|---|
데이터 불러오기 : 변수/상수 (0) | 2022.02.16 |
데이터 저장 : 객체 (0) | 2022.02.14 |
데이터 저장 : 배열 (0) | 2022.02.14 |
데이터 저장 : 변수/상수 (0) | 2022.02.10 |