I need to construct a long string with javascript. Thats how i tried to do it:
var html = '<div style="balbalblaba"> </div>';
for(i = 1; i <= 400; i++){
html+=html;
};
When i execute that in firefox its taking ages or makes it crash. what is the best way to do that? What is generally the best way to construct big strings in JS.
can someone help me?
I assume you mean
html += html;.If you do that, your
htmlstring’s length will be 37 × 2400 = 9.5 × 10121 which is beyond the limit of any browsers, on any computers, in any[1] known universes can handle.If you just want to repeat that string 400 times, use
or
See Repeat String – Javascript for more options.
[1]: As in “this universe”.