how to repeat a function for the length of an array in javascript code example Example: repeat an element in array in js Array(5).fill(2) //=> [2, 2, 2, 2, 2]