> For the complete documentation index, see [llms.txt](https://april.gitbook.io/learning-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://april.gitbook.io/learning-js/chapter-6./6.3/6.3.2.md).

# 6.3.2 매개변수 해체

* 객체, 배열을 변수로 해체할 수 있음
* 확산 연산자(...)를 써서 남는 매개변수를 이용할 수 있음

### 1) 객체를 변수로 해

```javascript
const o1 = {
    subject: "I",
    verb: "love",
    object: "javascript"
};

function getSentence ({ subject, verb, object }) {
  return subject + " " + verb + " " + object;
}

console.log(getSentence(o1)); // "I love javascript"
```

### 2) 배열을 변수로 해

```javascript
const arr1 = [ "I", "Love", "Javascript" ];

function getSentence2 ([ subject, verb, object ]) {
  return subject + " " + verb + " " + object;
}

console.log(getSentence2(arr1)); // "I love javascript"
```

### 3) 확산 연산자(...)를 써서 남는 매개변수를 이용

**단, 함수를 선언할 때 확산 연산자는 반드시 마지막 매개변수여야 함**<br>

```javascript
function addPrefix(prefix, ...words) {
  const prefixedWords = [];

  for (let i=0; i<words.length; i++) {
    prefixedWords[i] = prefix + words[i];
  }

  return prefixedWords;
}

console.log(addPrefix("con", "verse", "vex")); ["converse", "convex"]
```
