Javascript:在页面上打印1,000,000“o”s

我一直试图在页面上打印1,000,000个“o”,但它不断崩溃。有没有一种快速和简单的方式打印1,000,000 o的没有使用图像?Javascript:在页面上打印1,000,000“o”s

回答:

使用String.prototype.repeat

const n = 100; // set this to 1000000 later  

document.write('o'.repeat(n))

Array.prototype.fill

const n = 100; // set this to 1000000 later  

document.write(new Array(n).fill('o').join(''))

回答:

更快

const n = 1000000; // set this to 1000000  

document.write("o".repeat(n))

以上是 Javascript:在页面上打印1,000,000“o”s 的全部内容, 来源链接: utcz.com/qa/260668.html

回到顶部