在Python中我可以使用:
s = "x" * 10
xxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
在JavaScript中,如何在没有循环的情况下创建一个字符串n个字符长?
使用 String.repeat
"x".repeat(10);
Run Code Online (Sandbox Code Playgroud)
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
在旧浏览器上你可以做到
new Array(10).join('x')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1547 次 |
| 最近记录: |