0

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);
});

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.