To create an array with same element repeated multiple times with JavaScript, we call the fill
method.
For instance, we write
const arr = Array(15).fill(2);
to create an empty array with 15 slots with Array
.
And then we call fill
to fill all the slots with 2’s.