Array.copyWithin

copyWithin — Copies a subset of the array and pastes over the array's current values starting at target.

Description

Array.copyWithin(integer target, integer start, [integer end])

Parameters

Name Description Type Default Optional
target integer No
start integer No
end integer Yes

Return values

The array with the filled values.

Changelog

Version Description
ES 6 Introduced.

Examples

Example #1 – copyWithin example

The array is overwritten when filling.

var array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.copyWithin(1, 1)); // [2, 4, 8, 4, 16, 4, 32] console.log(array); // [2, 4, 8, 4, 16, 4, 32] array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.copyWithin(1, 3, 5)); // [2, 4, 16, 4, 16, 4, 32] console.log(array); // [2, 4, 16, 4, 16, 4, 32] array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.copyWithin(0, 1, 5)); // [4, 8, 4, 16, 16, 4, 32] console.log(array); // [4, 8, 4, 16, 16, 4, 32]

External references