---
# System prepended metadata

title: "\U0001F3C5 Day 25 - forEach"
tags: [JS 直播班 - 2023 秋季班]

---

---
tags: JS 直播班 - 2023 秋季班
---
# 🏅 Day 25 - forEach

[`forEach()`](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) 是屬於 **「陣列」** 的方法，會將陣列內的每個元素一一傳入，並依序執行函式。 `forEach()` 內的函式常見會帶有三個參數，以下為用法示例：
```javascript=
let data = ["a", "b", "c"];

// 參數 item 代表陣列中目前正在被處理的那個元素
// 參數 index 代表陣列中目前正在被處理的那個元素的索引值
// 參數 array 代表被處理的陣列本身，在此為 data
data.forEach(function(item, index, array){
  console.log(item, index, array);
})
```
執行結果:
![](https://i.imgur.com/NuRNgjX.png)



**這邊需要特別提醒，在 `forEach()` 函式內用 return 無法停止函式進行下一個 item。除非程式碼有誤，否則並沒有中止 `forEach()` 的辦法**

```javascript=
let data = ["a", "b", "c"];

data.forEach(function(item, index, array){
  console.log(item, index, array);
  // 程式碼會忽略這個 return 
  return
})
```


問題
---
請根據以下要求撰寫程式碼:
> 1. 如果 numberAll 陣列內的值大於或等於 30，則用 `push()` 方法將其加入 NumberAbove30 陣列中。
> 2. 如果 numberAll 陣列內的值小於 30，則用 `push()` 方法將其加入 numberUnder30 陣列中。

```javascript=
let numberAll = [25, 30, 15, 50, 17, 40];
let numberAbove30 = [];
let numberUnder30 = [];

numberAll.forEach(function(/* 填入參數 */){
  if (/* 填入判斷式 */) {
    /* 程式碼撰寫處 */
  } else {
    /* 程式碼撰寫處 */
  }
});
console.log(numberAbove30);
console.log(numberUnder30);
```

## 回報流程

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

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

<!-- 解答：  


let numberAll = [25, 30, 15, 50, 17, 40];
let numberAbove30 = [];
let numberUnder30 = [];

//forEach

numberAll.forEach(function(item) {
  if (item >= 30) {
    numberAbove30.push(item);
  } else {
    numberUnder30.push(item);
  }
});
console.log(numberAbove30);
console.log(numberUnder30);

-->




回報區
---


|     Discord     |                                CodePen / 答案                                |
|:---------------:|:----------------------------------------------------------------------------:|
|詹姆士|[CodePen](https://codepen.io/z111048/pen/MWLmojj)|
|⭐️小正|[CodePen](https://codepen.io/colorgolden/pen/bGzWRBb?editors=1111)|
|銀光菇|[CodePen](https://codepen.io/genesynthesis/pen/RwvVgGq)|
|Ching|[CodePen](https://codepen.io/tzuchingg/pen/WNPjOjv?editors=0011)|
|Morning|[CodePen](https://codepen.io/sxzjnkxs-the-styleful/pen/yLZbXPV?editors=0011)|
|Moreene|[CodePen](https://codepen.io/Moreene/pen/ZEwKyMJ)|
|yuling|[Codepen](https://codepen.io/igzdflpu/pen/MWLmoPo?editors=1011)|
|rickTsaiii|[Codepen](https://codepen.io/ricktsaiii/pen/poGPwBw?editors=1111)|
|yuan2781|[Codepen](https://codepen.io/ismebir/pen/vYbmZqo)|
|cest_jessie|[Codepen](https://codepen.io/itsjessiechen/pen/qBgmOxy)|
|CPing|[Codepen](https://codepen.io/CPing/pen/QWYvMjv?editors=1111)|
|pinyi_9|[Codepen](https://codepen.io/Wpypy/pen/poGPrzr?editors=1011)|
|Peng|[Codepen](https://codepen.io/H-Peng/pen/OJdmjXX)|
|yuan!|[Codepen](https://codepen.io/townyuan/pen/abXWyBP)|
| hus0921 | [Codepen](https://codepen.io/HSUANIN0327/pen/MWLmvpG) |
| Alyce | [Codepen](https://codepen.io/alycehwy/pen/poGPrLV?editors=0010) |
| Helen | [Codepen](https://codepen.io/milkteamonster/pen/ZEwKJjm?editors=1010) |
| Andy | [Codepen](https://codepen.io/andy31342/pen/QWYvqjV?editors=0011) |
| ming0712 | [Codepen](https://codepen.io/StevenHuang/pen/wvNdrMj?editors=0010) |
| 維哲 | [Codepen](https://codepen.io/kwz1202/pen/gOqWGrX) |
| Chia Pin | [Codepen](https://codepen.io/joker-cat/pen/WNPjZGa) |
| Winnie | [Codepen](https://codepen.io/codepen-io-winnie/pen/MWLmEJM?editors=0011) |
| RX00 | [Codepen](https://codepen.io/llqzknqv-the-styleful/pen/eYxWGEY?editors=0011) |
| Yijing | [Codepen](https://codepen.io/Yi-Jing-71080635/pen/RwvVLLj?editors=0011) |
| stone4584 | [Codepen](https://codepen.io/Royen0506/pen/PoVmJLy?editors=1111) |
| xin | [Codepen](https://codepen.io/Estherrrrrr999/pen/OJdmOMG) |
| claire | [Codepen](https://codepen.io/yi-wen-chen/pen/vYbmWJv) |
| tanuki5863 | [Codepen](https://codepen.io/tanuki320/pen/LYqyeQP?editors=1011) |
| kawa | [Codepen](https://codepen.io/z83xji6/pen/xxMdpvx?editors=1011) |
| sponge | [Codepen](https://codepen.io/biunpujm-the-flexboxer/pen/ExrmQZj?editors=1111) |
| kuanju27 | [Codepen](https://codepen.io/Eero-Chiao/pen/oNmWEMw) |
|風羽|[Codepen](https://codepen.io/Joy-Huang/pen/BaMRYbv?editors=0011)|
|ann6212|[Codepen](https://codepen.io/yqmegupa-the-styleful/pen/QWYvmWL?editors=1010)|
| Uli| [Codepen](https://codepen.io/uli1313/pen/ExrmENv) |
| dora | [Codepen](https://codepen.io/dorayu/pen/VwgbxWw?editors=1011) |
|阿榮|[Codepen](https://codepen.io/codeitaday/pen/RwvVydo)|
| 荷菓かのり | [Codepen](https://codepen.io/oogxwkvw-the-builder/pen/PoVmaqJ?editors=1112) |
| MY | [Codepen](https://codepen.io/ahmomoz/pen/VwgbGYO?editors=1111) |
| yu.t_liu | [Codepen](https://codepen.io/YuT200053/pen/abXWPva?editors=1111) |
|celinelinnn|[Codepen](https://codepen.io/celinephoebe/pen/qBgmLQW)|
| lychee_kk | [Codepen](https://codepen.io/kakakala/pen/xxMdNgw) |
| Tina02 | [CodePen](https://codepen.io/chjitlox-the-bashful/pen/gOqmLXB) |
| runweiting | [Codepen](https://codepen.io/weiting14/pen/rNPmENL) |
| jiayu | [Codepen](https://codepen.io/fjqxaznl-the-reactor/pen/mdvmZWQ) |
| 小夏 | [Codepen](https://codepen.io/michaelhsia/pen/qBgmzzJ) |
|Eden|[Codepen](https://codepen.io/iseden/pen/bGzWXXa)|
| 精靈 | [Codepen](https://codepen.io/justafairy/pen/Rwvgbex) |
| ROGAN | [Codepen](https://codepen.io/RoganHsu/pen/XWOgJEx?editors=1011) |
| JUNEW | [Codepen](https://codepen.io/June-W/pen/mdvweBa) |
| Fabio20 | [Codepen](https://codepen.io/fabio7621/pen/rNPwMqq) |
| 保羅 | [Codepen](https://codepen.io/paul-1997/pen/abXwBVO?editors=0011) |
| 奔跑吧(GTR150) | [Codepen](https://codepen.io/Wer-Qwe/pen/JjxJbpX?editors=1111) |
| JasonFu | [Codepen](https://codepen.io/jie-Fu/pen/JjxJJap) |
| Ataraxia | [Codepen](https://codepen.io/ataraxia8888/pen/VwgjXGp) |
| shuuu | [Codepen](https://codepen.io/afjrvjzl-the-bashful/pen/KKJqQeJ?editors=1011) |
| Oria | [Codepen](https://codepen.io/kajing/pen/gOqRKgR?editors=1011) |
| 依依 | [Codepen](https://codepen.io/Rita-Yang/pen/XWOgYNw?editors=0011) |
| damon0323 | [Codepen](https://codepen.io/swk9eny2/pen/vYbZrQJ?editors=0011) |
| santu0868 | [Codepen](https://codepen.io/HatsumiSan/pen/abXyKJr?editors=1111) |
| phyllis | [CodePen](https://codepen.io/gmoxhrmc-the-styleful/pen/JjxymNg)|
|xiaokui_71292|[CodePen](https://codepen.io/pen?template=NWoaaVY)|
|郭芙蘭#6374|[CodePen](https://codepen.io/flora_Kuo/pen/dyaVJvj?editors=1011)|
|   Jerry  | [Codepen](https://codepen.io/ildkosxk-the-encoder/pen/ZEwXrvM?editors=0010) |
|   Joy-chiang  | [Codepen](https://codepen.io/fwysphbw-the-vuer/pen/bGzoMEP?editors=0010) |
|_shun0130|[CodePen](https://codepen.io/koba60052ww/pen/MWLELrG?editors=0011)
| Mattie|[CodePen](https://codepen.io/mattielin/pen/bGzYEKG)|
| shcopy |[CodePen](https://codepen.io/shcopy/pen/MWLOvqb)|
|yaoling.liang|[CodePen](https://codepen.io/Yao-Ling-L-/pen/jOdaKYw?editors=0012)|
|歐陽龍龍#1061|[CodePen](https://codepen.io/dizzydog-rgb/pen/BaMmORb)|
|Iris|[CodePen](https://codepen.io/iris831206/pen/bGzLryJ?editors=1112)|
|xuan|[CodePen](https://codepen.io/xuan0915/pen/rNPJddQ?editors=1011)|
|ChrisSQR|[CodePen](https://codepen.io/ChrisSQR/pen/qBgxKWP)|
|Vivian2857|[CodePen](https://codepen.io/vivian_lin/pen/qBgxgmx?editors=1012)|
|jimmy.0706|[CodePen](https://codepen.io/WeiJun-Mao/pen/PoVQVEr?editors=0010)|
|阿賀#3700|[CodePen](https://codepen.io/sungho/pen/jOdzwNV)|
|Daylily|[CodePen](https://codepen.io/daylily/pen/JjxvPNJ)|
|Lainie|[CodePen](https://codepen.io/Lainie88/pen/rNPvpqE?editors=1010)|
|Rochel|[Codepen](https://codepen.io/rochelwang1205/pen/KKJePZO?editors=0011)|
|Hank._.z|[Codepen](https://codepen.io/linoiaby-the-sans/pen/zYeaGjB?editors=1111)|
|nini1202desu|[Codepen](https://codepen.io/tvxq5206/pen/mdvjWjV?editors=0011)|
|macihuang|[Codepen](https://codepen.io/macy1215/pen/OJdwrRV)|
|bf_tsai|[Codepen](https://codepen.io/BF-Tsai/pen/eYxLmQK?editors=0010)|
|NathanJames|[Codepen](https://codepen.io/ufo060204/pen/VwgEYqO)|
|skypassion5000|[Codepen](https://codepen.io/skypassion5000/pen/YzBJoBY?editors=0011)|
| 辣椒 | [Codepen](https://codepen.io/chilichen118/pen/GRzwYBo) |
|阿榮|[Codepen](https://codepen.io/codeitaday/pen/LYqMzqv)|
|nikkita_3544|[Codepen](https://codepen.io/vanessa7259/pen/zYeyyQw?editors=0011)|
| 雪維 | [Codepen](https://codepen.io/Shawey/pen/xbKzGXP) |

<!--
複製以下行數即可回報
 |  | [Codepen]() | 
-->