Create an array with same element repeated multiple times

In ES6 using Array fill() method

console.log(
  Array(5).fill(2)
)
//=> [2, 2, 2, 2, 2]

Leave a Comment