1

With Google Apps Script, I like to add a 2D array to the end of an existing 2D array. But the following codes returned a 3D array with another nest inside, like “ [['AAPL', 'Strong'], ['MSFT', 'Strong'], [[ 'TSLA', 'Weak'], ['VZ', 'Neutral']]]”. I want the 2D output, like [['AAPL', 'Strong'], ['MSFT', 'Strong'], ['TSLA', 'Weak'], ['VZ', 'Neutral']]. What should be changed in the codes! Thank you for any guidance!

function test() {
  var data1 = [['AAPL', 'Strong'], ['MSFT', 'Strong']];
  var data2 = [['TSLA', 'Weak'], ['VZ', 'Neutral']];
  var output = data1;
  output.push(data2);
  console.log(output);
}

1 Answer 1

1
var output = data1.concat(data2);

Reference:

Array.prototype.concat()

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.