티스토리 뷰

Javascript

데이터 불러오기04

babydeveloper 2022. 3. 7. 08:50

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

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

    document.write(obj.hasOwnProperty('a'));
    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);
    document.write('d' in obj);
    //데이터 안의 내용이 있는지 없는지 확인할때 사용한다.
}

결괏값

true
true
true
false
true
true
true
false

19. 객체 : 데이터 불러오기 : 펼침 연산자 - 복사

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

    document.write(spread.a);
    document.write(spread.b);
    document.write(spread.c);
}

결괏값

100
200
javascript

20. 객체 : 데이터 불러오기 : 펼침 연산자 - 추가

{
    const obj = {
        a: 100,
        b: 200,
        c: "javascript"
    }
    const spread = { ...obj, d: "jquery" }

    document.write(spread.a);
    document.write(spread.b);
    document.write(spread.c);
    document.write(spread.d);
}

결괏값

100
200
javascript
jquery

21. 객체 : 데이터 불러오기 : 펼침 연산자 - 결합

{
    const objA = {
        a: 100,
        b: 200,
        
    }
    const objB = {
        c: "javascript",
        d: "jQuery"
    }
    const spread = { ...objA, ...objB }

    document.write(spread.a);
    document.write(spread.b);
    document.write(spread.c);
    document.write(spread.d);
}

결괏값

100
200
javascript
jQuery

22. 객체 : 데이터 불러오기 : 비구조화 할당

{
    const obj = {
        a: 100,
        b: 200,
        c: "javascript"
    }
    const { a,b,c } = obj;
    document.write(a);
    document.write(b);
    document.write(c);
}

결괏값

100
200
javascript

23. 객체 : 데이터 불러오기 : 비구조화 할당 : 이름별도저장

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

    document.write(name1);
    document.write(name2);
    document.write(name3);
}

결괏값

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

 

자바스크립트 데이터 불러오기 예제 18번부터 23번까지입니다.

데이터 불러오기예제는 이것으로 끝입니다!!!!

데이터불러오는 다양한 방법 23가지를 알아봤으니 다음엔~ 무엇을 알아볼까요!18~23번 말고도 다양한 방법이 궁금하시다면 참조사이트를 참고하시면 좋을거 같아요!

반응형

'Javascript' 카테고리의 다른 글

자바스크립트 전역변수와 지역변수  (0) 2022.04.14
자바스크립트 출력  (1) 2022.04.14
데이터 불러오기03  (0) 2022.03.07
Javascript - mouseover 와 mouseleave 차이점  (0) 2022.02.25
데이터 불러오기02  (0) 2022.02.21
댓글
© 2022 babydevelop