Repeat an array with multiple elements multiple times in JavaScript Repeat an array with multiple elements multiple times in JavaScript arrays arrays

Repeat an array with multiple elements multiple times in JavaScript


No need for any library, you can use Array.from to create an array of arrays you want repeated, and then flatten using [].concat and spread:

const makeRepeated = (arr, repeats) =>  [].concat(...Array.from({ length: repeats }, () => arr));  console.log(makeRepeated([1, 2, 3], 2));