# スプレッド構文とは

[ECMAScript 2015](https://tips.weseek.co.jp/5e39820de848c600487d6a24) で定義された構文。

関数呼び出しでは 0 個以上の引数として、Array リテラルでは 0 個以上の要素として、  
Object リテラルでは 0 個以上の key-value のペアとして、Array や String などの iterable オブジェクトをその場で展開する

```javascript:example.js
// Array
const odd = [1, 3]
const even = [2, 4]
const numbers = [...odd, ...even]
console.log(numbers) // [1, 3, 2, 4]

//Object
const name = {first: "Tanaka", last: "Taro"}
const age = {age: 27}
const profile = {...name, ...age}
console.log(profile) // {first: "Tanaka", last: "Taro", age: 27}
```
配列やオブジェクトをコピーするだけでなく、**マージすることが簡単に**できる。  
配列であれば `hoge.concat()`  
オブジェクトであれば、 `Object.asign()`   
を使い実現していたことを、短い記述で同様のことを実現できる。

```javascript:example.js
// Array
const numbers = odd.concat(even)

// Object
const profile = Object.assign(name, age)
```

## 参考
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Spread_syntax

---

## Page Navigation

- Canonical URL: https://tips.weseek.co.jp/用語集/Javascript/スプレッド構文
- Permalink: https://tips.weseek.co.jp/5e39828be848c600487d6a27
- Parent: [Javascript](/5e392e88e848c600487d69db.md)
- Children: 0 total
- Total descendants: 0
- Siblings: 14 total
  - [Angular](/5e393953e848c600487d6a04.md)
  - [ECMAScript](/5e39820de848c600487d6a24.md)
  - [Object_entries ](/5e3f9391f5921400485be6a8.md)
  - [React](/5e3930c8e848c600487d69ed.md)
  - [Setオブジェクト](/5e4252bbdecd0a0049953aea.md)
  - [Svelte](/5e3980bde848c600487d6a1e.md)
  - [Vue](/5e3930f3e848c600487d69f0.md)
  - [protypeMethodのmap()とforEach()の違い](/5e57b3b07887d100480949fe.md)
  - [protypeMethodのthen()について](/5f163aac647aac00495efa7d.md)
  - [throttle-debouceのthrottleとdebouceの違い](/5e785068f78b4b0048b6add1.md)
  - [ローカルストレージ](/5e86b4db139099004805819c.md)
  - [分割代入](/5e3af26c25751e0049929801.md)
  - [宣言（varとletとconstの違い）](/5e5de1da3051ce00499cac5e.md)
  - [正規表現](/5e633bb4d9ebf700489783ea.md)
- Last updated: 2020-03-06T15:59:56.151Z by deleted_at_1672138397219
- Full page listing (all children regardless of count): https://tips.weseek.co.jp/_api/v3/page-listing/children?id=5e39828be848c600487d6a27
