repeat element in array javascript code example
Example 1: javascript repeat element in array
Array(5).fill(2)
//=> [2, 2, 2, 2, 2]
Example 2: repeat an element in array in js
Array(5).fill(2)
//=> [2, 2, 2, 2, 2]
Array(5).fill(2)
//=> [2, 2, 2, 2, 2]
Array(5).fill(2)
//=> [2, 2, 2, 2, 2]