---
# System prepended metadata

title: 去最外層陣列方式：for...of迴圈&&展開運算子
tags: [ALPHACampWeek6_學期2-2]

---

###### tags:`ALPHACampWeek6_學期2-2`

# 去最外層陣列方式：for...of迴圈&&展開運算子

## for...of迴圈
- 示範一
```jsx=
const movies = [];
axios.get(INDEX_URL).then(response =>{
  for(const movie of response.data.results){
    movies.push(movie);
  }
})
```

## 展開運算子
* 示範一
```jsx=
const movies = [];
axios.get(INDEX_URL).then(response => {
  movies.push(...response.data.results);
  console.log(movies);
})
```
- 示範二
```jsx=
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output: 6
```