Let's assume that you have the following array:
javascriptlet group = ['jeff', 'bill', 'elon', 'erik']
To copy the array n times at the end of it (concatenate n times):
javascriptlet copy = group.join('__join__').concat('__join__').repeat(5).split('__join__')
The problem of the previous option is that you could have an array such as ['jeff', '__join__', 'bill']
.
A better option:
javascriptlet copy = 'n'.repeat(3).split('').reduce(acc => acc.concat(group), [])
Result:
javascript// ['jeff', 'bill', 'elon', 'erik', 'jeff', 'bill', 'elon', 'erik', 'jeff', 'bill', 'elon', 'erik']
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.