# 🏅 Day 14 - 物件取值 在物件內新增、修改、取得屬性的方法有以下兩種: 1. 點記法 (Dot notation) ```javascript= let obj = {}; obj.key = "value"; // 新增或修改 console.log(obj.key); // 取得 ``` 2. 括弧記法 (Bracket notation) ```javascript= let obj = {}; // 當屬性的值帶有小數點、空格或是數字時可以使用,記得要加上引號 (單引號或雙引號皆可) obj['k e y'] = "value"; // 新增或修改 console.log(obj['key']); // 取得 ``` ### 題目 請觀看下方程式碼,依照註解敘述完成程式碼(補上 `...` 的部分): ```javascript= let weather = { country: "高雄", "PM2.5": 35, isSunny: false, rainingRegion: ['鼓山', '鹽埕', '旗津'], rainFall: { 鼓山: 400, 鹽埕: 300, } } // 取得 country 的值,並使用 console.log 印出 console.log(...); // 取得 "PM2.5" 的值,並使用 console.log 印出 console.log(...); // 取得 isSunny 的值,並使用 console.log 印出 console.log(...); // 取得 rainingRegion 陣列的第一個值 '鼓山',並使用 console.log 印出 console.log(...); // 在 rainFall 新增一個屬性名為「旗津」、設定值為 200,並,並使用 console.log 印出 rainFall 的值 ... console.log(rainFall); ``` ## 回報流程 將答案寫在 CodePen 並複製 CodePen 連結貼至底下回報就算完成了喔! 解答位置請參考下圖(需打開程式碼的部分觀看)  <!-- 解答: // 取得 country 的值 console.log(weather.country); // 方法一 console.log(weather["country"]); // 方法二 // 取得 "PM2.5" 的值 console.log(weather["PM2.5"]); // 取得 isSunny 的值 console.log(weather.isSunny); // 方法一 console.log(weather["isSunny"]); // 方法二 // 取得 rainingRegion 陣列的第一個值 '鼓山' console.log(weather.rainingRegion[0]); // 在 rainFall 新增一個屬性名為「旗津」、設定值為 200,並輸出結果 weather.rainFall.旗津 = 200; // 方法一 console.log(weather.rainFall); weather["rainFall"]["旗津"] = 200; // 方法二 console.log(weather["rainFall"]); --> 回報區 --- | # | Discord | CodePen / 答案 | |--|--|--| | 1. | Wayne_957 | [Codepen](https://codepen.io/Wayne957/pen/raBqpdr?editors=0011) | | 2. | pja._. | [CodePen](https://codepen.io/PJA0103/pen/JoPmMZV?editors=0011) | | 3. | CC(tofuuu_cat) | [CodePen](https://codepen.io/CC-cat/pen/NPKOXJa?editors=0012) | | 4 | daffytseng | [Codepen](https://codepen.io/Daffy-Tseng/pen/vEBVdOK) | | 5. | sui_hsilan | [CodePen](https://codepen.io/suihsilan/pen/ogvaEOW?editors=1012) | |6.|Nora| [CodePen](https://codepen.io/ehguhcmy-the-reactor/pen/MYgPQMg?editors=1111) | | 7. | Tau | [CodePen](https://codepen.io/Tau-Hsu/pen/JoPmLGN?editors=0012) | | 8. | JanllyGuo | [CodePen](https://codepen.io/kedugaw/pen/YPKJaej?editors=0011) | | 9. | adengg | [CodePen](https://codepen.io/Osases/pen/ogvaqdd?editors=0012) | | 10. | bian_yang_mofa | [CodePen](https://codepen.io/cssf998811/pen/azoRYrq?editors=0011) | | 11 | potato_17859 | [CodePen](https://codepen.io/Girl-Lee/pen/KwPGZey?editors=0012) | | 12. | HarryKuo | [CodePen](https://codepen.io/harry_kuo/pen/ZYzqoev?editors=0012) | | 13. | ss585801 | [CodePen](https://codepen.io/ss585801/pen/yyBxBde?editors=0011) | | 14. | will092317 | [CodePen](https://codepen.io/xuazoblx-the-flexboxer/pen/raBqKWb?editors=0012) | | 15. | JerryOOO | [CodePen](https://codepen.io/fatiangel/pen/ogvaMyd?editors=0011) | | 16. | Tammy | [CodePen](https://codepen.io/Tammy_Tsai/pen/OPLBoxN) | | 17. | poyi | [CodePen](https://codepen.io/poyi-the-flexboxer/pen/ByBqOgR?editors=0012) | | 18 | janetlai | [CodePen](https://codepen.io/eiddkqxz-the-builder/pen/bNbmOpE?editors=0111) | 19 | yutzu | [CodePen](https://codepen.io/dtafsrmf-the-lessful/pen/gbYBZJw?editors=0010) | 20 | Xuan | [CodePen](https://codepen.io/YiXuan-Chen-the-vuer/pen/ogvQgEO) | | 21 | ZoeKang|[CodePen](https://codepen.io/byehywmx-the-animator/pen/WbeYvoM?editors=0011) | 22. | 地呱 | [Codepen](https://codepen.io/wiibxzdw-the-bold/pen/mybQzEP?editors=0012) | | 23. |ally_tsao| [Codepen](https://codepen.io/ggnhmrxv-the-scripter/pen/jENQjxg?editors=0012)| | 24. |helena| [Codepen](https://codepen.io/helena27/pen/KwPbzLG?editors=1012)| | 25. | Lee | [CodePen](https://codepen.io/leemo-tseng/pen/yyBGazg?editors=1112) | | 26. | Ali | [CodePen](https://codepen.io/Alicia1117/pen/RNbEZEz) | | 27. | shiang | [CodePen](https://codepen.io/shiang29/pen/ogvJVLL?editors=0011) | | 28. | benson | [CodePen](https://codepen.io/DevilButler/pen/jENdLoM?editors=0011) | | 29. | Arsian Kuo | [CodePen](https://codepen.io/Arsian-Kuo/pen/pvzGKqL)| | 30. | JC | [CodePen](https://codepen.io/lifetimingwhisper/pen/YPKBmyE)| | 31 | 0111 | [CodePen](https://codepen.io/0111mina/pen/yyBwPKQ?editors=0011) | | 32 | Rylee | [CodePen](https://codepen.io/ryleezheng/pen/PwYvoRb) | 33 | hsin yu | [CodePen](https://codepen.io/tina2793778/pen/mybYRBJ?editors=0011) | | 34 | chun0075 | [CodePen](https://codepen.io/Lin-Angela/pen/mybYyqq) | | 35 | hsiang4100 | [CodePen](https://codepen.io/vvnrbgxl-the-typescripter/pen/yyBWXGE?editors=0012) | | 36 | wuyuli_21403 | [CodePen](https://codepen.io/Job-Wilhelm/pen/zxYGjjz) | | 37 | li-wei-min | [CodePen](https://codepen.io/leewayne/pen/azbvgYe?editors=1111) | <!-- 可複製下方格式 | | | [CodePen]() | -->
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up