Repeat Character N Times

后端 未结 23 2789
栀梦
栀梦 2020-11-22 11:51

In Perl I can repeat a character multiple times using the syntax:

$a = \"a\" x 10; // results in \"aaaaaaaaaa\"

Is there a simple way to ac

23条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 12:33

    Array(10).fill('a').join('')
    

    Although the most voted answer is a bit more compact, with this approach you don't have to add an extra array item.

提交回复
热议问题