객체 모르는 부분...!
function accessObject() {
// 아래의 코드를 수정하지마세요.
let myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
// 아래의 코드를 수정해주세요.
let gloveBoxContents =
myStorage['car']['inside']['glove box'];
// gloveBoxContents["glove box"]
// 아래의 코드를 수정하지마세요.
return gloveBoxContents;
}
이해가 잘 안갔는데 스터디원께서 이렇게 알려주셨다.
(1) 대괄호 표기법
let gloveBoxContents =
myStorage['car']['inside']['glove box'];
(2) 대괄호 표기법 + Object.values(obj)
let obj = myStorage['car']['inside'];
//[object Object] {
//glove box: "maps",
//passenger seat: "crumbs"
//}
let gloveBoxContents = Object.values(myStroge)[0]; // value 값만 가져옴
=> ["maps", "crumbs"]
Object.values(obj);
Object.keys(obj);
Object.entries(obj); => 키, 밸류 둘다 구하는
{ -> 0 index
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
} -> a
================
{ -> 1 index
type: "trees",
list: [
"fir",
"pine",
"birch"
]
} -> b
=> arr [a, b]
arr[1] === b
myPlants[1] => object./[]
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
.list -> myPlants[1].list = [ "fir", "pine", "birch" ]
myPlants[1].list[1] => "pine"
one step