Skip to content
Subhajit Sahu edited this page Mar 8, 2020 · 25 revisions

Repeat array n times, like String.repeat().

const repeat = require('@extra-array/repeat');
// repeat(<array>, [times=1], [begin=0], [end], [target=[]], [at])

repeat(['a', 'b'], 3);
// ['a', 'b', 'a', 'b', 'a', 'b']
repeat(['a', 'b', 'c', 'd'], 2, 1);
// ['b', 'c', 'd', 'b', 'c', 'd']
repeat(['a', 'b', 'c', 'd'], 2, 1, 3);
// ['b', 'c', 'b', 'c']
repeat(['a', 'b', 'c', 'd'], 2, 1, 3, ['z', 'y']);
// ['z', 'y', 'b', 'c', 'b', 'c']
repeat(['a', 'b', 'c', 'd'], 2, 1, 3, ['z', 'y'], 1);
// ['z', 'b', 'c', 'b', 'c']

With extra-array try Array.repeat() instead.


extra-array

Clone this wiki locally