티스토리 뷰
11. 배열 : 데이터 불러오기 : 펼침 연산자
{
const num = [100, 200, 300, 400, 500];
document.write(num); //100, 200, 300, 400, 500
document.write(num[0], num[1], num[2], num[3], num[4]); // 100200300400500
document.write(...num); // 100200300400500
}
결괏값
100,200,300,400,500
100 200 300 400 500
100 200 300 400 500
12. 배열 : 데이터 불러오기 : 배열구조분해할당
{
let a, b, c;
[a, b, c] = [100, 200, "javascript"];
document.write(a);
document.write(b);
document.write(c);
}
결괏값
100
200
javascript
13. 객체 : 데이터 불러오기 : 기본
{
const obj = {
a: 100,
b: 200,
c: "javascript"
}
document.write(obj.a);
document.write(obj.b);
document.write(obj.c);
document.write(obj['a']); //죽은문법
document.write(obj['b']);
document.write(obj['c']); //
}
결괏값
100
200
javascript
100
200
javascript
14. 객체 : 데이터 불러오기 : Object
{
const obj = {
a: 100,
b: 200,
c: "javascript"
}
document.write(Object.keys(obj));
document.write(Object.values(obj));
document.write(Object.entries(obj));
}
결괏값
a,b,c
100,200,javascript
a,100,b,200,c,javascript
15. 객체 : 데이터 불러오기 : 변수
{
const obj = {
a: 100,
b: 200,
c: "javascript"
}
const name1 = obj.a;
const name2 = obj.b;
const name3 = obj.c;
document.write(name1);
document.write(name2);
document.write(name3);
}
결괏값
100
200
javascript
16. 객체 : 데이터 불러오기 : for in
{
const obj = {
a: 100,
b: 200,
c: "javascript"
}
for( let key in obj) {
document.write(obj[key]);
}
}
결괏값
100
200
javascript
17. 객체 : 데이터 불러오기 : map()
{
const obj = [
{a: 100, b: 200, c: "javascript"}
]
obj.map(function(el){
document.write(el.a);
document.write(el.b);
document.write(el.c);
});
}
결괏값
100
200
javascript
참조사이트
자바스크립트
결과보기 100 200 300 400 500 100 0 100,200,300,400,500 200 1 100,200,300,400,500 300 2 100,200,300,400,500 400 3 100,200,300,400,500 500 4 100,200,300,400,500
parkjongho1.github.io
자바스크립트 데이터 불러오기 예제 11번부터 17번까지입니다.
데이터를 불러오는 다양한 방법에 다양한 방법이 있고 다른 방법들은 참조사이트를 들어가셔서 참고하시면 좋습니다!
반응형
'Javascript' 카테고리의 다른 글
자바스크립트 출력 (1) | 2022.04.14 |
---|---|
데이터 불러오기04 (1) | 2022.03.07 |
Javascript - mouseover 와 mouseleave 차이점 (0) | 2022.02.25 |
데이터 불러오기02 (0) | 2022.02.21 |
데이터 불러오기01 (0) | 2022.02.21 |
댓글
© 2022 babydevelop