how many times string repeated in array javascript code example
Example 1: duplicate an array in javascript n times
const makeRepeated = (arr, repeats) =>
Array.from({ length: repeats }, () => arr).flat();
console.log(makeRepeated([1, 2, 3], 2));
Example 2: javascript create array with repeated values
Array(5).fill(2)
//=> [2, 2, 2, 2, 2]