Return to Snippet

Revision: 44492
at April 12, 2011 22:12 by root_hacker


Initial Code
function repeat(str,n)
{
return new Array(n+1).join(str);
}

repeat("<li class='empty'>" , 2);


//output: "<li class='empty'><li class='empty'>"

Initial URL

                                

Initial Description
when need to created a dom element repeatedly , use string concatenation to avoid for loop you can use repeat function from below.

Initial Title
javascript: create DOM element without using for loop

Initial Tags
javascript, best

Initial Language
JavaScript