---
# System prepended metadata

title: "\U0001F3C5 JS 任務 Day22 - forEach"
tags: [軟體工程師體驗營 - 2023]

---

---
tags: 軟體工程師體驗營 - 2023
---

# 🏅 JS 任務 Day22 - 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 是無效的。除非程式碼有誤，否則並沒有中止 `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);
```


## 回報流程

1. 將答案貼在 Codepen 並複製 Codepen 連結貼至「回報區」回報
（也可以將答案直接貼至「回報區」）

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

<!-- 解答：  


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

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


回報區
---

| 報數 | Discord 名字  |  Codepen／其他回饋                                                         |
|:----:|:-------------------:|:---------------------------------------------------------------------------------------------------------------------------------:|
| 1 | 翔.#0859 | [Codepen](https://codepen.io/energy95272z/pen/BaqbqQO?editors=0012) |
| 2 | 神秘人#0888 | [Codepen](https://codepen.io/engineerjohnson/pen/vYVPVpR)|
| 3 | Rochel#4754 | [Codepen](https://codepen.io/rochelwang1205/pen/Rwedexy?editors=1010) |
| 4 | Berlin#7338 | [Codepen](https://codepen.io/3qberlin/pen/poxYxqj?editors=0010) |
| 5 | DeLi#8324 | [Codepen](https://codepen.io/delichaomoon/pen/ZEqPqVO) |
| 6 | Quantum#6093 | [Codepen](https://codepen.io/Min-Hao-Hung/pen/eYPXQYv) |
| 7 | Nex#6093 | [Codepen](https://codepen.io/Samuel_D4C/pen/JjmzePM) |
| 8 | JimWang#6134 | [Codepen](https://codepen.io/Jim-Wang-the-selector/pen/GRYewQK?editors=0012) |
| 9 | Jacky7035#9423 | [Codepen](https://codepen.io/adens123/pen/gOBEQjb) |
| 10 | snow#0255 | [Codepen](https://codepen.io/snow21723/pen/VwERqvw) |
| 11 | 冬天#5215 | [Codepen](https://codepen.io/winter_/pen/poxYqgL) |
| 12 | Eero#1147 | [Codepen](https://codepen.io/Eero-Chiao/pen/oNaVJZg) |
| 13 | Akira#9996 | [Codepen](https://codepen.io/Akira-Chen/pen/JjmzwLj) |
| 14 | ChaosTu#9311 | [Codepen](https://codepen.io/torotu/pen/OJBqrvj?editors=0012) |
| 15 | 姜承#8204 | [Codepen](https://codepen.io/Troy0718/pen/bGmZOyK) |
| 16 | jia yu#8896 | [Codepen](https://codepen.io/fjqxaznl-the-reactor/pen/qBJvgYX?editors=1111) |
| 17 |peihsuan#6315|[Codepen](https://codepen.io/peihsuanlai/pen/oNaVmpG) |
| 18 |Ataraxia#9977|[Codepen](https://codepen.io/ataraxia8888/pen/qBJPWag) |
| 19 |Uli#1946|[Codepen](https://codepen.io/uli1313/pen/dygrrzw) |
| 20 |Billy_Ti#9716|[Codepen](https://codepen.io/Ti-Show/pen/VwERRMg?editors=0012) |
| 21 |K（アギルダー）#0386|[Codepen](https://codepen.io/klay376014/pen/jOeJJzy) |
|22|肉個阿倫#7172|[Codepen](https://codepen.io/i9574385/pen/jOeJJoL)|
|23|jimhop#6510 | [Codepen](https://codepen.io/pen/?editors=1111)
|24|Jennifer Chuang#3937|[Codepen](https://codepen.io/yujhen/pen/rNqRXzo?editors=1111)|
|25| 銀光菇#1692 | [Codepen](https://codepen.io/genesynthesis/pen/dygrLqM)|
|26| 司機叔叔#2463 | [Codepen](https://codepen.io/bigv5566/pen/KKGYKwV?editors=1111)|
| 27 | 辣椒#1002 | [Codepen](https://codepen.io/chilichen118/pen/rNqbaXX) |
| 28 | yoyo#1003 | [Codepen](https://codepen.io/pen/VwENKNK) |
| 29 | David0799#4415 | [Codepen](https://codepen.io/David0799/pen/OJBGbyv?editors=0010) |
| 30 | 兔子#6746 | [Codepen](https://codepen.io/CarrotDetector/pen/eYPojOz) |
| 31 | SKey#9905 | [Codepen](https://codepen.io/Dale-Chien/pen/vYVMoRN) |
| 32 | 喬喬#2824 | [Codepen](https://codepen.io/joanne-wei/pen/gOByVzw) |
|33| 鄭舜仁#6606 | [Codepen](https://codepen.io/randomno/pen/PoyvoOv) |
| 34 | 東東#5015 |[Codepen](https://codepen.io/wearymask/pen/GRYaoMo)|
|35|Yvonne#2721|[Codepen](https://codepen.io/Evonne/pen/mdzYPpq?editors=0010)
|36|HsuanTang#1349|[Codepen](https://codepen.io/HsuanTang/pen/RwemRGY)
|37|Janet#5784|[Codepen](https://codepen.io/janetlinnn/pen/Exdzybv?editors=1111)
|38|FanJJ#8061|[Codepen](https://codepen.io/yfchenn/pen/PoyvqjQ?editors=0011)
39|雲漢#5319|[codepen](https://codepen.io/keon981/pen/qBJGPWB)
|40|Kulimusoda#2785|[codepen](https://codepen.io/yuch3n_chen/pen/PoyvEPw?editors=0011)|
|41|gahwa#3562|[codepen](https://codepen.io/gahwa17/pen/abRrYRE)|
|42|PayRoom#8328|[CodePen](https://codepen.io/water38198/pen/eYPwmxj)|
|43|Snadra#1987|[CodePen](https://codepen.io/mlqmhltg/pen/zYmVJvE)|
|44|townyuan#2653|[CodePen](https://codepen.io/townyuan/pen/gOBNQqZ)|
|45|勁霖#1602|[CodePen](https://codepen.io/townyuan/pen/gOBNQqZhttps://codepen.io/nickwu1229/pen/NWOZJWL?editors=0011)|
|46|liam9930#4129|[CodePen](https://codepen.io/jgnjfvvt-the-lessful/pen/XWyWzmo?editors=0012)|
|47|JasonChang#7847|[CodePen](https://codepen.io/jsonChangJava/pen/PoxqPjz)|
| 48 | Kaya#8857 | [Codepen](https://codepen.io/laron9486/pen/QWJymRd) |
| 49 | jun777#2468 | [Codepen](https://codepen.io/js18151102/pen/wvQWYNj?editors=0011) |
| 50 | PoWei#8484 | [Codepen](https://codepen.io/harrison-wei-lai/pen/GRwmBMp?editors=1012) |
| 51 | Ann Chou#0146 | [Codepen](https://codepen.io/annchou_illu/pen/VwVzMbW) |
| 52 | 小明#4408 | [Codepen](https://codepen.io/ujlylmbv-the-lessful/pen/gOQKvBN) |
| 53 | hoyiiiii | [Codepen](https://codepen.io/hoyii/pen/mybVrOe) |
