You could create an array of length whatver you want and then use the join()
method on the array which will make it into a string. Array(number).join(char)
this creates an array on size number -1
. Also note that you do not want to use your method because concatenating strings is very expensive(O(n) every concat). I am not sure if javascript has a StringBuilder like java