How to repeat array values N times in JavaScript

1 Answer

0 votes
let arr = ["a", "b", "c", "d"];
 
const N = 3;
arr = [].concat(...Array(N).fill(arr));
    
console.log(arr);



/*
run:

["a", "b", "c", "d", "a", "b", "c", "d", "a", "b", "c", "d"]  

*/

 



answered May 20, 2021 by avibootz

Related questions

1 answer 123 views
2 answers 216 views
1 answer 174 views
1 answer 202 views
1 answer 75 views
1 answer 97 views
...