JavaScript String Concatenation Speed Enhancment

By Robbe Morris
INSTANTLY dtSearch TERABYTES OF POPULAR DATA TYPES; hundreds of reviews, etc.!

JavaScript String Concatenation Speed Enhancment

Here's a quick little example based on the VBScript article here at eggheadcafe.com designed to give you faster string concatenation capabilites.


Here's a quick little example based on the VBScript article here at eggheadcafe.com designed to give you faster string concatenation capabilites.

Here's the VBScript sample:

http://www.eggheadcafe.com/articles/20011227.asp

Here's the JavaScript sample that uses an Array object. The .push() method adds
the string to the end of the array. The .join() method converts the Array object
to a string represenation. I've chosen a blank space as the delimiter arguement.
You can put any character you like as the delimiter.

With large strings, your speed will improve drastically...

<script language=javascript>

var oInputArray = new Array();
var sH='';

oInputArray.push("string 1");
oInputArray.push("string 2");
oInputArray.push("string 3");

sH = oInputArray.join(' ');
alert(sH);


</script>


Submission Date:  9/23/2005 2:54:49 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

Popularity  (73 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of EggHeadCafe.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP