JavaScript 배열 copyWithin()
예
처음 두 개의 배열 요소를 마지막 두 개의 배열 요소에 복사합니다.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.copyWithin(2, 0);
처음 두 배열 요소를 세 번째 및 네 번째 위치에 복사합니다.
const fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.copyWithin(2, 0, 2);
정의 및 사용
이 copyWithin()
메서드는 배열 요소를 배열의 다른 위치에 복사합니다.
메서드 는 copyWithin()
기존 값을 덮어씁니다.
이 copyWithin()
메서드는 배열에 항목을 추가하지 않습니다.
통사론
array.copyWithin(target, start, end)
매개변수
Parameter | Description |
target | Required. The index (position) to copy the elements to. |
start | Optional. The start index (position). Default is 0. |
end | Optional. The end index (position). Default is the array length. |
반환 값
유형 | 설명 |
배열 | 변경된 배열입니다. |
브라우저 지원
copyWithin()
ECMAScript6(ES6) 기능입니다.
ES6(JavaScript 2015)은 모든 최신 브라우저에서 지원됩니다.
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
copyWithin()
Internet Explorer 11(또는 이전)에서는 지원되지 않습니다.