Nested Objects
Objects inside objects.
Examples
Accessing Nested Object
Accessing deep properties.
const myObj = {
name: "John",
cars: {
car1: "Ford",
car2: "BMW"
}
}
console.log(myObj.cars.car2);Modifying Nested Object
Changing a value inside a nested object.
const myObj = {
cars: {
car1: "Ford"
}
}
myObj.cars.car1 = "Tesla";
console.log(myObj.cars.car1);Test Your Knowledge
JavaScript Quiz
No quiz available for this topic yet.