> For the complete documentation index, see [llms.txt](https://shhn0509.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shhn0509.gitbook.io/javascript/js-upgrade/curious-story/array-protection.md).

# 원본 배열을 왜 보호해야 할까?

원본 배열을 참조하는 다른 변수가 있을 경우 문제가 유발될 수도 있고, 다시 이전 상태로 되돌리기 위한 변수가 필요할 수도 있다. 원본 배열을 보호한 채, 정렬 된 새로운 배열을 사용하려면? 먼저 배열 복사가 필요합니다.

`slice()`, `map()` 등을 사용하여 배열을 복사한 뒤, 가공한다.&#x20;

```javascript
originalArray.slice().sort(function (x, y) {
  return x - y;
});
```
