2017-03-08 63 views
-4

我一直試圖在頁面上打印1,000,000個「o」,但它不斷崩潰。有沒有一種快速和簡單的方式打印1,000,000 o的沒有使用圖像Javascript:在頁面上打印1,000,000「o」s

+2

顯示你的代碼。 –

+0

爲什麼你需要/想要在一頁上打印1000000個o? – d3L

+2

並不是每個程序員都需要100萬個頁面嗎? –

回答

2

使用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(''))

+0

Ahhh毆打我。 – xanth

+0

@xanth我坐在這裏*「必須有一個粘性的方式」* – Phil

1

更快

const n = 1000000; // set this to 1000000 
 
document.write("o".repeat(n))