|
| 1 | +var myDog = { |
| 2 | + "name": "Coder", // Here it will work if you write - name: "Coder", as well |
| 3 | + "legs": 4, |
| 4 | + "tails": 2, |
| 5 | + "friends": ["Debugger", "Designer"], |
| 6 | +} |
| 7 | +myDog.name = "Pro Coder" // Changing a property value |
| 8 | +myDog.bark = "Bow Bow" // Adding a new Property |
| 9 | + |
| 10 | +console.log(myDog.name) // Pro Coder |
| 11 | +console.log(myDog.friends[1]) // Designer |
| 12 | +console.log(myDog["legs"]) // 4 |
| 13 | +console.log(myDog["friends"][0]) // Debugger |
| 14 | +console.log(myDog[0]) // undefined |
| 15 | +console.log(myDog.bark) // Bow Bow |
| 16 | +console.log(myDog['bark']) // Bow Bow |
| 17 | +// console.log(myDog[bark]) // it will through an error saying bark is not defined |
| 18 | + |
| 19 | +// Delete a property from an object |
| 20 | +console.log(myDog) |
| 21 | +delete myDog.bark |
| 22 | +console.log(myDog) |
0 commit comments