[Solved] Copy content of one array to another arry


I’d suggest to go with guest271314 answer. But if you want to multiply it more than twice, and you’re looking for an alternative solution, you can also do it like,

var arr = [1,2,3,4];

var dupeTimes = 2;
var newArr = JSON.parse(JSON.stringify(arr).repeat(dupeTimes).replace(/\]\[/g, ','))
console.log(newArr); // [1, 2, 3, 4, 1, 2, 3, 4]

dupeTimes = 10;
newArr = JSON.parse(JSON.stringify(arr).repeat(dupeTimes).replace(/\]\[/g, ','))
console.log(newArr); // [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]

1

solved Copy content of one array to another arry