JavaScript - Object 객체

🦜 eunhye_k·2022년 2월 16일
1
post-thumbnail

💡 Object(객체)란?

object(객체)property(속성)를 가진 데이터를 저장해주며, { } 를 사용한다.
list는 공통된 속성들을 나열하지만 object는 다른 속성들을 나열 할 수 있다.
ex) list = 요일 / object = 이름, 나이, 주소…

	const player = {
		name: tomato,
		color: red,
		food: true
	};

	console.log(player);

1. Property(속성) 불러오기

	console.log(player.name); => tomato
	console.log(player["name"]); => tomato

2. Property(속성) 변경하기

	const player = {
		name : tomato,
		color : red,
		food : true
	};

	console.log(player);
	player.color = "blue";
	console.log(player.color); //blue

🚨 참고!
const의 경우 재할당하는 것은 불가능하지만 property를 바꾸는 것은 가능하다.

3. Property(속성) 추가하기

player.koreanName = "토마토";
player["koreanName"] = "토마토"; // player["변수"] = "토마토" 변수로도 사용가능

//{name: "tomato", color: "blue", food: true, koreaName: "토마토"}

👋 마치며

스터디 활동을 위해 기록하고 있습니다.
다르거나 추가해야할 내용이 있다면 언제든지 코멘트 남겨주세요 :)

✉ dmsp1234@gmail.com

📍 참고



profile
UI/UX 디자인을 공부하는 퍼블리셔 입니다 (●'◡'●)

2개의 댓글

comment-user-thumbnail
2022년 2월 17일

스터디 화이팅입니당

답글 달기
comment-user-thumbnail
2022년 2월 19일

👍👍👍

답글 달기