array.prototype.concat
array.prototype.filter
주어진 배열에서 조건에 부합하는 요소를 모아 새로운 배열로 반환한다. 어떤 요소도 조건에 부합하지 않으면 빈 배열을 반환한다.
array.prototype.map
배열 내의 모든 요소 각각에 대하여 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환하다.
array.from
배열을 얕게 복사해 새로운 배열 객체를 만든다.
array.prototype.slice
얕은 복사로 새로운 배열 객체로 반환한다. 원본 배열은 바뀌지 않는다.
array.prototype.sort
배열의 요소를 적절한 위치에 정렬한 후 그 배열을 반환한다. 원본 배열을 정렬한다. 복사본이 만들어지지 않는다.
array.prototype.fill
배열의 모든 요소를 정적인 값으로 채운다. 원본 배열을 채워넣기 때문에 복사본이 만들어지지 않는다.
array.prototype.forEach
배열의 모든 요소에 대해 실행하고 반환값은 undefined이다.
array.prototype.reduce
누적된 결과값을 반환한다.
array.prototype.pop
배열의 마지막 요소를 제거하고 제거한 요소를 반환한다. 원본 배열을 제거하기 때문에 주의해야한다.
array.prototype.shift
배열의 첫 번째 요소를 제거하고 제거된 요소를 반환한다. 원본 배열을 제거하기 때문에 주의해야한다.
array.prototype.push
원본 배열에 요소를 추가하고 배열의 새로운 길이를 반환한다.
array.prototype.unshift
원본 배열의 첫 번째 요소에 추가하고 배열의 새로운 길이를 반환한다.
array.prototype.splice
배열의 기존 요소를 삭제 또는 교체하거나 새 요소를 추가하여 원본 배열의 내용을 변경한다.
JSON.parse(JSON.stringify(obj))로 깊은 복사
spread 사용하여 복사
const original = {
a: 1,
b: 2,
c: {
d: 3,
},
}
const copied = { ...original }
original.a = 1000
original.c.d = 3000
console.log(copied.a) // 1
console.log(copied.c.d) // 3000
object.create
const original = {
a: 1,
b: 2,
c: {
d: 3
}
};
const copied = Object.create(original);
original.a = 1000;
original.c.d = 3000;
console.log(copied.a); // 1000
console.log(copied.c.d); // 3000