1

How do I aggregate in Angular multiple arrays into one? I don't want to concatenate/merge them, but keep them separated with a comma.

var data1 = [65, -59, 80, 81, -56, 55, -40];
var data2 = [28, 48, -40, 19, 86, 27, 90];

Expected:

data = [
[65, -59, 80, 81, -56, 55, -40],
[28, 48, -40, 19, 86, 27, 90]
];

2 Answers 2

1

This is not an Angular questions but a javascript question, and while there are many ways to solve this, I will give you one.

var mergedData = [];
var data1 = [65, -59, 80, 81, -56, 55, -40];
var data2 = [28, 48, -40, 19, 86, 27, 90];
mergedData.push(data1);
mergedData.push(data2);

The variable mergedData will now contain

[
    [65, -59, 80, 81, -56, 55, -40],
    [28, 48, -40, 19, 86, 27, 90]
]
Sign up to request clarification or add additional context in comments.

Comments

0

You can create a new array to hold the data, and then just push your arrays into that new array like this:

var data = []
data.push(data1,data2)

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.