Reputation: 27221
What is the best solution to concate lots of strings? I wanna get a lot of information from my mongodb database and send via email. I have a lot of data to concate. The usual way is:
var str1 = "Hello ";
var str2 = "world!";
var res = str1.concat(str2);
I have some array:
var strs = {'str0','str1','str2',.....};
I need something like this:
asyncConcate(strs,function (result)
{
console.log(result);
});
Upvotes: 0
Views: 68
Reputation: 2310
try this code and see if it helps:
(used node.js async module https://github.com/caolan/async)
var async = require("async");
var finalResult = "";
var strArray = ["str1","str2","str3"];
var limit = strArray.length-1;
async.forEachLimit(strArray,limit,function(item,callback){
finalResult+=item;
callback();
});
console.log(finalResult);
Upvotes: 2