Create a string of variable length, filled with a repeated character

前端 未结 10 1121
刺人心
刺人心 2020-11-28 03:59

So, my question has been asked by someone else in it\'s Java form here: Java - Create a new String instance with specified length and filled with specific character. Best so

10条回答
  •  生来不讨喜
    2020-11-28 04:46

    I would create a constant string and then call substring on it.

    Something like

    var hashStore = '########################################';
    
    var Fiveup = hashStore.substring(0,5);
    
    var Tenup = hashStore.substring(0,10);
    

    A bit faster too.

    http://jsperf.com/const-vs-join

提交回复
热议问题