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

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

    ES2015 the easiest way is to do something like

    'X'.repeat(data.length)

    X being any string, data.length being the desired length.

    see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat

提交回复
热议问题