JavaScript 객체 기본 - 객체

Deong_gu·2022년 3월 27일
0
post-thumbnail

부스트코스 강의 - 생활코딩님의 자바스크립트의 시작

강의 중 객체에 대해서 공부하던 중, 헷갈리는 부분이 생겨서 객체 파트를 다시 점검하게되었습니다.

객체

● 서로 연관된 변수와 함수를 그룹핑하고 이름을 붙인 것.
● 속성을 통해 여러 개의 값을 하나의 단위로 구성한 복합적인 자료구조.
● 변경 가능한 값
● 자료를 저장하고 처리하는 기본 단위 (복합자료형)

객체 생성

const brandObject = {
    IT: 'samsung',
    shoes: 'nike',
    trainning: 'adidas',
    'mouse': 'logetech',
    badminton: 'lonex'
}

객체 수정 및 추가

// 프로퍼티(키) 값 수정, 추가
brandObject.badminton = 'YONEX'; 
console.log(brandObject.badminton);
//배열과는 다른 객체에서 값을 불러오는 방법(.프로퍼티, ['프로퍼티'])
console.log('brandObject.IT', brandObject.IT);
console.log("brandObject['shoes']", brandObject['shoes']); // console.log("brandObject[shoes]", brandObject[shoes]);//ReferenceError: shoes is not defined
console.log(brandObject['trainning']);
console.log(brandObject);
// {mouse: } ,{'mouse': } 비교
console.log('brandObject.mouse', brandObject.mouse); // console.log("brandObject['mouse']",brandObject[mouse]); ReferenceError: mouse is not defined
console.log("brandObject['mouse']",brandObject['mouse']);

객체 삭제

//객체 프로퍼티 삭제
delete brandObject.mouse;
console.log(brandObject);
// {
//     IT: 'samsung',
//     shoes: 'nike',
//     trainning: 'adidas',
//     badminton: 'YONEX'
// }
profile
프론트엔드 개발자가 되기 위해 공부 중입니다.

0개의 댓글