JRS: In article <Uy*****************@news.optus.net.au>, dated Fri, 8
Oct 2004 05:27:16, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.auau> posted :
var a = [];
var i = 0;
a[0] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
If you use i++ rather than ++i, then the first line can have the same
LHS as the rest, and the first para will be paragraph 1 - ISTM.
How about
var s = [
" <p>here is paragraph " + 1 + "</p>",
" <p>here is paragraph 2 </p>",
" <p>here is paragraph 3 </p>",
...
"" ].join("") ;
taking the view that self-numbering paragraphs are probably not needed?
The empty string is to allow the previous line to end, like the rest,
with a comma, which seems nicer.
I've not tested for speed.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.