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

前端 未结 10 1132
刺人心
刺人心 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:28

    A great ES6 option would be to padStart an empty string. Like this:

    var str = ''.padStart(10, "#");
    

    Note: this won't work in IE (without a polyfill).

提交回复
热议问题