노마드 코더/바닐라 자바스크립트
초보자를 위한 바닐라 자바스크립트 #1-10
KDONG
2021. 8. 24. 19:44

Object란?
각 value에 이름을 줄 수 있다.
Object를 선언하기 위해서는 {컬리 브라켓}을 써주면 된다.
const nicoInfo = {
name:"Nico",
age:33,
gender:"Male",
isHandsome:true,
}
console.log(nicoInfo.gender)
//Male
선언 한 뒤 다시 선언하면 데이터가 변경되서 출력하는걸 확인할 수 있다.
const nicoInfo = {
name:"Nico",
age:33,
gender:"Male",
isHandsome:true,
}
nicoInfo.gender = "Female"
console.log(nicoInfo.gender)
//Female
객체안에 배열을 넣을 수 있다. 또한, 배열안에 객체를 넣을 수 있다.
const nicoInfo = {
name:"Nico",
age:33,
gender:"Male",
isHandsome:true,
favMovies: ["Along the gods", "LOTR", "Oldboy"],
favFood: [
{name: "Kimchi", fatty: false},
{name: "Cheese burger", fatty: true}
]
};
console.log(nicoInfo.favFood[0].name);
console.log(nicoInfo.favFood[1]);
//Kimchi
//{name: "Cheese burger", fatty: true}