Thursday, November 23, 2006

Efficient String Concatenation in JS

In .NET, we use StringBuilder if we need to concatenate strings for better string manipulation performance. For instance,

StringBuilder builder = new StringBuilder();
builder.append("This");
builder.append("is");
builder.append("really");
builder.append("good");
builder.append("for");
builder.append("performance");

string str = builder.ToString();

In JS, we can also do the same thing for better memory allocation in string concatenation too.

var builder = new Array();
builder.push("This");
builder.push("is");
builder.push("really");
builder.push("good");
builder.push("for");
builder.push("performance");

var str = builder.join("");


This method will perform faster if the number of string concatenation is huge. THe normal += operator will win, otherwise.

Check Efficient JavaScript for more information on optimizing JS code

6 comments:

Suseela Susiee said...


Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.


SAP HR training in Chennai

Merlin Maarit said...



It is very helpful for me. Keep blogging like this.


Healthcare Analytics Company

Finance Analytics Company

Telecom Analytics Company

Retail Analytics Company

Analytics Company

US IT Staffing Agency

Karthi Keyan said...


Its fantatic explaintion lot of information gather it...nice article....
seo company in Chennai

deeksha said...

very very amazing explaintion....many things gather about yourself...yes realy i enjoy it
Base SAS Training in Chennai

Philips Huges said...



Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

Personal Installment Loans
Title Car loan
Cash Advance Loan

sunitha vishnu said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
Android Training in Chennai
Ios Training in Chennai