---
# System prepended metadata

title: "\U0001F3C5 Day 35 - 多筆物件取值"
tags: [JS 直播班 - 2022 秋季班]

---

---
tags: JS 直播班 - 2022 秋季班
---
# 🏅 Day 35 - 多筆物件取值

### Object.keys(), Object.values() 使用練習

* Object.keys() 可以取得指定物件的所有 key 值，並回傳一個陣列。
* Object.values() 可以取得指定物件的所有 value 值，並回傳一個陣列。

```javascript=
const object1 = {
  a: "字串",
  b: 42,
  c: false
};

console.log(Object.keys(object1));   // 結果: ["a", "b", "c"]
console.log(Object.values(object1)); // 結果: ["字串", 42, false]
```

問題
---

請練習使用 Object.keys()，修改資料格式，並存入名稱為 answer 的物件，格式如下圖：

![](https://i.imgur.com/7pA41y0.png)

範例程式碼：
```javascript=
let answer = {}; // 請把修改完的資料存入 answer 物件。
let url = "https://raw.githubusercontent.com/hexschool/js-traninging-week6API/main/data.json";
axios.get(url)
  .then(function(response) {
    let total = {};
    let data = response.data;

    data.forEach(function(item, i) {
      if(total[item.jsGroup] === undefined) {
        total[item.jsGroup] = 1;
      } else {
        total[item.jsGroup] += 1;
      }
    });
    
    // 將整理好的 total 資料調整成圖中的格式存入 answer 中
    /* 程式碼開始 */


    /* 程式碼結束 */
    
    console.log(answer);
  });
```



## 回報流程

將答案寫在 CodePen 並複製 CodePen 連結貼至底下回報就算完成了喔! 
解答位置請參考下圖（需打開程式碼的部分觀看）

![](https://i.imgur.com/vftL5i0.png)

<!-- 解答：  

```
let answer = {};
let url = "https://raw.githubusercontent.com/hexschool/js-traninging-week6API/main/data.json";
axios.get(url)
  .then(function(response) {
    let total = {};
    let data = response.data;

    data.forEach(function(item, i) {
      if(total[item.jsGroup] === undefined) {
        total[item.jsGroup] = 1;
      } else {
        total[item.jsGroup] += 1;
      }
    });

    let keyName = Object.keys(total);
    keyName.forEach(function(item) {
      if(item !== "未分組") {
        answer[`第 ${item} 組人數`] = total[item];
      } else {
        answer[`${item}人數`] = total[item];
      }
    });
    console.log(answer);
  });
```
-->




回報區
---


|        Discord        |                                CodePen / 答案                                |
|:---------------------:|:----------------------------------------------------------------------------:|
|      albee#9121       |      [Codepen](https://codepen.io/albee-chang/pen/oNyGVWN?editors=1012)      |
|       薯餅#3581       |            [Codepen](https://codepen.io/albee-chang/pen/oNyGVWN)             |
|        YC#2522        |                [CodePen](https://codepen.io/YCLu/pen/ZERyLoY)                |
|      Arista#5802      |            [CodePen](https://codepen.io/arista-hsieh/pen/QWxONGj)            |
|    suihsilan#9485     |       [CodePen](https://codepen.io/suihsilan/pen/LYrONEQ?editors=0010)       |
|      Kimi #9564       |              [CodePen](https://codepen.io/kimihu91/pen/KKeqoMb)              |
|       yumy#1940       |              [CodePen](https://codepen.io/yumyyang/pen/ZERaWYp)              |
|    hsiung阿熊#4079    |             [Codepen](https://codepen.io/hsiungchi/pen/eYKeZvW)              |
|       威0#6919        |      [codepen](https://codepen.io/n0918679182/pen/QWxONdj?editors=0012)      |
|      Loran#1105       |              [codepen](https://codepen.io/loranlin/pen/PoaONQY)              |
|       RJRS#9430       |                [CodePen](https://codepen.io/RJRS/pen/MWXOyJb)                |
|      Clara#1275       |       [CodePen](https://codepen.io/bsupixqu/pen/JjZOXOZ?editors=1011)        |
|     AuroraC#6539      |        [codepen](https://codepen.io/AuroraC/pen/jOKaqQy?editors=1112)        |
|     PayRoom#8328      |             [CodePen](https://codepen.io/water38198/pen/ZERXPam)             |
|       m_m#5493        |             [CodePen](https://codepen.io/minnn7716/pen/dyKZMmw)              |
|      楓之聲#6945      |             [Codepen](https://codepen.io/sshane258/pen/poKdyQP)              |
|     mandylai#4055     |      [Codepen](https://codepen.io/mandy-lai-2/pen/QWxONaE?editors=0012)      |
|      法希娜#3206      | [Codepen](https://codepen.io/yiiserpf-the-encoder/pen/ZERaWwa?editors=1011)  |
|     kenki100#0069     |               [Codepen](https://codepen.io/ken100/pen/dyKZXvy)               |
|      yawun#0042       |             [CodePen](https://codepen.io/monicalin/pen/abKVZWM)              |
|    LHchien33#6232     |             [CodePen](https://codepen.io/lin_chien/pen/oNyoLXR)              |
|      amy芳#1385       |             [CodePen](https://codepen.io/amy-chieng/pen/KKeyMoR)             |
|       大衛#4869       |       [CodePen](https://codepen.io/exnsrpjc/pen/BaVmKry?editors=1011)        |
|       威爾#1694       |              [CodePen](https://codepen.io/WILL_Wu/pen/yLEPJvq)               |
|       柔柔#1716       |        [Codepen](https://codepen.io/rouchen/pen/dyKZXdo?editors=1011)        |
|    Potatolee#7749     |      [Codepen](https://codepen.io/potatoleee/pen/YzvEWxy?editors=1011)       |
|       kuku#3118       |            [Codepen](https://codepen.io/mengting-ku/pen/KKeyMYG)             |
|    Ron Liang#7277     |               [Codepen](https://codepen.io/ron-go/pen/wvXPzzx)               |
|      Hilda#7085       |         [Codepen](https://codepen.io/vwquikad-the-vuer/pen/oNyozXz)          |
|      Benson#6763      |              [Codepen](https://codepen.io/kumashow/pen/gOKXMQW)              |
|    jimmyFang#9575     |       [Codepen](https://codepen.io/pohxiqqo/pen/dyKZpJz?editors=1011)        |
|       圈圈#4060       |         [codepen](https://codepen.io/wjejfczn-the-bold/pen/NWzwRPB)          |
|      Winnie#1306      |    [Codepen](https://codepen.io/WinnieWuWinnie/pen/rNKYMZe?editors=0012)     |
|   William Lai#0196    |      [Codepen](https://codepen.io/lai-weihan/pen/qBKVqbx?editors=1111)       |
|    Yuna Huang#2692    |       [Codepen](https://codepen.io/Yuna1002/pen/rNKYMdO?editors=1011)        |
|    出事了阿伯#9923    |      [Codepen](https://codepen.io/BradpittLai/pen/yLEPVNO?editors=1011)      |
|       小白#2406       |             [CodePen](https://codepen.io/gracewhite/pen/YzvEGvY)             |
|    Ruby Chen#7452     |       [Codepen](https://codepen.io/ruby92429/pen/XWYzjvp?editors=0011)       |
|     WEI_RIO#9342      |        [CodePen](https://codepen.io/wei_wu/pen/JjZOKwo?editors=0012)         |
| charlottelee849#0366  |     [CodePen](https://codepen.io/charlotte-lee/pen/OJEOWLN?editors=0012)     |
|      黑白兔#0684      |             [CodePen](https://codepen.io/johnny329/pen/bGKYBxE)              |
|    Cookie SSS#6991    | [CodePen](https://codepen.io/sqhjikpa-the-selector/pen/PoaOzpb?editors=1012) |
|       雷雷#7844       |      [CodePen](https://codepen.io/lei-yi-jie/pen/yLEPgMK?editors=1011)       |
|       Vera#5592       |               [CodePen](https://codepen.io/skvera/pen/MWXOJbG)               |
|      Cream#3449       | [CodePen](h
|IreneY#0086|[codepen](https://codepen.io/HalfPlannedJourney/pen/abKqRdN)|ttps://codepen.io/frxdwbbi-the-sasster/pen/zYaPNjX?editors=1012)  |
|    JustinLiu#9699     |      [CodePen](https://codepen.io/justin0227/pen/vYrWxxJ?editors=0011)       |
|      粉蒸肉#6214      |       [Codepen](https://codepen.io/wrightyu/pen/oNyoZoW?editors=1011)        |
|     beta lin#1445     |              [CodePen](https://codepen.io/linbeta/pen/dyKZvLJ)               |
|    shinyhung#3825     |       [CodePen](https://codepen.io/sean_1215/pen/MWXOjeM?editors=1011)       |
|   jacky010080#0880    |     [CodePen](https://codepen.io/Yen-Jung-Chen/pen/PoaOmPL?editors=1012)     |
|      azami#5986       |               [CodePen](https://codepen.io/azami/pen/OJEOgXR)                |
|       無名#6427       |              [CodePen](https://codepen.io/Nomoney/pen/poKdNWN)               |
|    Sentiments#4883    |      [codepen](https://codepen.io/Sentiments/pen/ExRbvWV?editors=1011)       |
|      SASIMI#5099      |            [Codepen](https://codepen.io/sashimi1327/pen/JjZOLpQ)             |
|    masterYan#2480     |  [Codepen](https://codepen.io/htzwgoqt-the-looper/pen/ExRbEae?editors=1011)  |
|       shio#1414       |        [CodePen](https://codepen.io/shioyen/pen/BaVmeob?editors=1111)        |
|     Tuhacrt#0008      |              [codepen](https://codepen.io/Tuhacrt/pen/YzvYKza)               |
|       yoyo#1003       |            [codepen](https://codepen.io/pen/zYapOoZ?editors=1111)            |
| 軟綿綿 (๑•ᴗ•๑) ♡#3627 |     [CodePen](https://codepen.io/Connie-Chien/pen/bGKaGxr?editors=0010)      |
|      Mylène#2481      |            [Codepen](https://codepen.io/hamajibashi/pen/VwdyvYN)             |
|       yen#5757        |     [Codepen](https://codepen.io/TZU-HUANG-YEN/pen/oNdPgqY?editors=0012)     |
|     Silvialu#4521     |            [Codepen](https://codepen.io/Silvia091640/pen/PoaEbNx)            |
| Rr#2215                      |  [Codepen](https://codepen.io/rufangcheng/pen/WNyXjMr)                                                                            |
|       Peng#9811       |              [Codepen](https://codepen.io/peng-027/pen/WNydyJN)              |
|       CofCat#9226       |              [Codepen](https://codepen.io/cofcat456/pen/WNydKWZ?editors=1011)              |
|Amberhh#2465|[Codepen](https://codepen.io/Amberhh/pen/qBKpKMo?editors=1010) |
|yoshidc#0455|[CodePen](https://codepen.io/yoshiyyc/pen/MWXQNEq) |
|Chung#5951|[CodePen](https://codepen.io/yuju16/pen/ExREVrp?editors=1011) |
| Jenny真#7532 | [CodePen](https://codepen.io/wei-chen-wu/pen/QWxmywg?editors=0011) |
|sophiee#7015|[codepen](https://codepen.io/sophiee2727/pen/ExREPNr?editors=1111)|
|Paul#7426|[CodePen](https://codepen.io/paul-1997/pen/WNyzVpj?editors=0011)|
|kevin#6131|[CodePen](https://codepen.io/xlqjezvc-the-encoder/pen/rNKvNxM?editors=1012)|
|Yiru#0236|[Codepen](https://codepen.io/yiru94/pen/vYrjmze?editors=1011)|
|Baozi#2042|[Codepen](https://codepen.io/lillianyu/pen/VwdxzYR)|
|Rena#6249|[Codepen](htps://codepen.io/aureate0116/pen/MWXGGMB?editors=1111)|
|黑松胖#4836|[Codepen](https://codepen.io/yi-chien-hsieh/pen/XWYYJgE?editors=0012)|
|kancheng#3915|[CodePen](https://codepen.io/kancheng/pen/GRGGoWK?editors=1112)|
|竹輪#3335|[CodePen](https://codepen.io/chikuwa0120/pen/vYrrWar)|
|予予#9627|[CodePen](https://codepen.io/kiqzcraa/pen/Poaardx?editors=10120)|
|Ryan Chiang#6649|[Codepen](https://codepen.io/ryanchiang/pen/OJEwLJX?editors=0012)|
|Judy Wei#6103|[Codepen](https://codepen.io/Judy0718/pen/WNyKReK)|
| Eileen#6454 |[Codepen](https://codepen.io/Eileen-io/pen/abKGqRd)|
|Cliff#4606|[Codepen](https://codepen.io/Cliff_hex/pen/OJEopQY?editors=0011)|
|yaru#6308|[CodePen](https://codepen.io/lszaietc/pen/dyKdJZG?editors=1011)|
|Shuo#1596|[CodePen](https://codepen.io/chiangchungshuo/pen/dyKgWgB?editors=0011)|
|Yishan#4902|[CodePen](https://codepen.io/gdjrehhw-the-animator/pen/gOKZyYL?editors=0012)|
|狸貓#5863|[CodePen](https://codepen.io/tanuki320/pen/wvXQZwp?editors=1010)|
|  cbs#9007  |[Codepen](https://codepen.io/wasdjk/pen/BaVeZeX)|
|  蓁心#6229  |[Codepen](https://codepen.io/tlorfrnl-the-typescripter/pen/mdjbMga)|
|J_u_d_y#5993|[Codepen](https://codepen.io/J_u_d_y/pen/XWPgzEQ?editors=1111)|
|Bingsu#2362|[Codepen](https://codepen.io/pmyfr/pen/xxyGGOb?editors=1112)|
