Repeat Character N Times

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

    var stringRepeat = function(string, val) {
      var newString = [];
        for(var i = 0; i < val; i++) {
          newString.push(string);
      }
      return newString.join('');
    }
    
    var repeatedString = stringRepeat("a", 1);
    

提交回复
热议问题