객체 수정, 프로퍼티 추가, 삭제 중첩 객체 접근
let myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog.name = "Happy Coder"; // obj이름.key값 = " 수정값 "
let myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog["name"] = "Happy Coder"; //obj이름["key값"] = " 수정값 "
let myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog.color = "Black";
// [object Object] {
// color: "Black",
// friends: ["freeCodeCamp Campers"],
// legs: 4,
// name: "Coder",
// tails: 1
// }
let myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog["color"] = "Black";
// [object Object] {
// color: "Black",
// friends: ["freeCodeCamp Campers"],
// legs: 4,
// name: "Coder",
// tails: 1
// }
let myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
delete myDog.name
// [object Object] {
// friends: ["freeCodeCamp Campers"],
// legs: 4,
// tails: 1
// }
let myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
delete myDog["name"]
// [object Object] {
// friends: ["freeCodeCamp Campers"],
// legs: 4,
// tails: 1
// }
let myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
gloveBoxContents = myStorage["car"]["inside"]["glove box"];
console.log(gloveBoxContents); // "maps"
function accessArray() {
let myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
let foundValue = myPlants[1]["list"][1];
return foundValue;
}
console.log(accessArray()); // "pine"
<출처>
codegreeper
MDN