0

I want to concat two arrays. In the code below i am only getting txs_history array.

getFirstArray(function(txs) {
    getSecondArray(function(txs_history) {
        txs.concat(txs_history);
        res.send(txs_history);
    });    
});

From my knowledge i can guess that txs var can't be read inside getSecondArray and that's why it is only sent txs_history. I can't figure out how to solve this scope issue.

Regards,

1
  • If txs wouldn't be in scope, you'd get an exception that says so. Commented Oct 14, 2014 at 17:08

1 Answer 1

2

txs is in scope, but txs.concat() returns a new array and leaves the original txs unmodified. What you want is probably this:

getFirstArray(function(txs) {
    getSecondArray(function(txs_history) {
        var combined = txs.concat(txs_history);
        res.send(combined);
    });    
});
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.