2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Use Dot Notation to Access the Properties of an Object
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Use Dot Notation to Access the Properties of an Object
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
The following code will simply print `1` from the `obj` object.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
let obj = {
|
2019-07-24 00:59:27 -07:00
|
|
|
property1: 1,
|
|
|
|
property2: 2
|
2018-10-12 15:37:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
console.log(obj.property1);
|
|
|
|
```
|
|
|
|
|
|
|
|
Following this logic, use the `console.log` operation to print both `property1`and `property2`to the screen.
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
|
|
|
```javascript
|
2018-10-12 15:37:13 -04:00
|
|
|
let dog = {
|
|
|
|
name: "Spot",
|
|
|
|
numLegs: 4
|
|
|
|
};
|
|
|
|
// Add your code below this line
|
|
|
|
console.log(dog.name);
|
|
|
|
console.log(dog.numLegs);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|