Repeat Character N Times

后端 未结 23 2792
栀梦
栀梦 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:23

    For repeat a value in my projects i use repeat

    For example:

    var n = 6;
    for (i = 0; i < n; i++) {
        console.log("#".repeat(i+1))
    }
    

    but be careful because this method has been added to the ECMAScript 6 specification.

提交回复
热议问题