01. 변수 : 데이터 불러오기

변수에 값을 불러옵니다.

{
    let x = 100,
    y = 200,
    z = "javascript"

    document.write(x);
    document.write(y);
    document.write(z);
}
결과보기

02. 상수 : 데이터 불러오기

상수에 값을 불러옵니다. 상수는 const라고 표기하며 변경할 수 없습니다.

{
    const x = 100,
    y = 200,
    z = "javascript";

    document.write(x);
    document.write(y);
    document.write(z);
}
결과보기

03. 배열 : 데이터 불러오기

배열에 데이터 값을 불러옵니다.

{
    const arr = [100, 200, "javascript"];

    document.write(arr[0]);
    document.write(arr[1]);
    document.write(arr[2]);

}
결과보기

04. 배열 : 데이터 불러오기 : 2차 배열

배열속에 있는 2차 배열 데이터 값을 불러옵니다.

{
    const arr = [100, 200, ["javascript", "jquery"]];

    document.write(arr[0]);
    document.write(arr[1]);
    document.write(arr[2][0]); //javascript 출력
    document.write(arr[2][1]); //jquery 출력 
}
결과보기

05. 배열 : 데이터 불러오기 : 갯수 구하기

배열 데이터 값의 갯수를 구합니다.

{
    const arr = [100, 200, "javascript"];
            
    document.write(arr.length); //배열안 데이터수 출력
}
결과보기

06. 배열 : 데이터 불러오기 : for()문

배열 데이터 값을 반복문을 사용하여 가져옵니다.

{
    const arr = [100, 200, 300, 400, 500];

    document.write(arr[0]);
    document.write(arr[1]);
    document.write(arr[2]);
    document.write(arr[3]);
    document.write(arr[4]);
    
    for(let i=0; i < arr.length; i++){
            document.write(arr[i]);
    }
}
결과보기
100
200
300
400
500

100
200
300
400
500

07. 배열 : 데이터 불러오기 : forEach()

배열 데이터 값을 반복문을 사용하여 가져옵니다.

{
    const num = [100, 200, 300, 400, 500];

    num.forEach(function(el){
        document.write(el); 
    });

    num.forEach(function(element, index, array){
        document.write(element); //요소 
        document.write(index); //인덱스
        document.write(array); //배열 
    });
}
결과보기
100200300400500

100200300400500
01234
100, 200, 300, 400, 500 100, 200, 300, 400, 500 100, 200, 300, 400, 500 100, 200, 300, 400, 500 100, 200, 300, 400, 500

08. 배열 : 데이터 불러오기 : for of()

배열 데이터 값을 반복문을 사용하여 가져옵니다.

{
    const arr = [100, 200, 300, 400, 500];

    for(let i of arr ){
        document.write(i); //배열 출력 
    }
}
결과보기
100, 200, 300, 400, 500

09. 배열 : 데이터 불러오기 : for in()

배열 데이터 값을 반복문을 사용하여 가져옵니다.

{
    const arr = [100, 200, 300, 400, 500];

    for( let i in arr ){
        document.write(i); //index가 출력 
        document.write(arr[i]); //array가 출력 
    }
}
결과보기
01234
100200300400500

10. 배열 : 데이터 불러오기 : map()

배열 데이터 값을 반복문을 사용하여 가져옵니다.

{
    const arr = [100, 200, 300, 400, 500];

    arr.map(function(el){
        document.write(el);
        console.log(el); // 100, 200, 300, 400, 500 출력
    });

    arr.map(function(element, index, array){
        document.write(element); //요소 출력
        document.write(index); //인덱스 값 출력
        document.write(array); //배열 출력 
    });
}
결과보기
100200300400500

100200300400500
01234
100, 200, 300, 400, 500100, 200, 300, 400, 500100, 200, 300, 400, 500100, 200, 300, 400, 500100, 200, 300, 400, 500

11. 배열 : 데이터 불러오기 : 펼침연산자 (Spread Operator)

펼침연산자를 통해 데이터를 불러옵니다.

{
    const num = [100,200,300,400,500];
    document.write(num);
    document.write(num[0],num[1],num[2],num[3],num[4]); 
    document.write(...num); //펼침연산자 : 배열안 데이터를 하나씩 다 불러올 수 있음 
}
결과보기

12. 배열 : 데이터 불러오기 : 배열구조분해할당(Destructruing assignment)

배열구조분해할당을 통해 데이터를 불러옵니다.

{
    let a,b,c; //undefined
    [a,b,c] = [100,200,"javascript"]; //값을 넣어줌

    document.write([a]);
    document.write([b]);
    document.write([c]);
}
결과보기

13. 객체 : 데이터 불러오기 : 기본

객체를 불러옵니다.

{
    const obj = {
            a:100,
            b:200,
            c:"javascript"
    }

    document.write(obj.a);
    document.write(obj.b);
    document.write(obj.c);
}        
결과보기

14. 객체 : 데이터 불러오기 : Object

객체를 통해 데이터를 불러옵니다.

{
    const obj = {
            a:100,
            b:200,
            c:"javascript"
    }

    document.write(Object.keys(obj)); //key만 불러오기 (죽은문법임)
    document.write(Object.values(obj)); //value만 불러오기
    document.write(Object.entries(obj)); //key, value 모두 불러오기 
}
결과보기

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);
}
결과보기

16. 객체 : 데이터 불러오기 : for in

for in을 통해 데이터를 불러옵니다.

{
    const obj = {
        a:100,
        b:200,
        c:"javascript"
    }

    for(let i in obj){
        document.write(obj[i]);
    }
}
결과보기

17. 객체 : 데이터 불러오기 : map()

map()을 통해 객체 데이터를 불러옵니다.

{
    const obj = [
        {a:100, b:200, c:"javascript"}
    ];

    //obj.map(function(){});  기본형태 
    obj.map((el) => {
        document.write(el.a);
        document.write(el.b);
        document.write(el.c);
    });
}
결과보기

18. 객체 : 데이터 불러오기 : hasOwnProperty()

hasOwnProperty()을 통해 데이터를 불러옵니다.

{
    const obj = {
        a:100,
        b:200,
        c:"javascript"
    };

    document.write(obj.hasOwnProperty("a")); //안에 데이터 여부에 대해 true or false로 알려줌 
    document.write(obj.hasOwnProperty("b"));
    document.write(obj.hasOwnProperty("c"));
    document.write(obj.hasOwnProperty("d"));
    document.write("a" in obj); //약식 
    document.write("b" in obj);
    document.write("c" in obj);
}
결과보기