Reputation: 718
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]
];
Upvotes: 1
Views: 659
Reputation: 6963
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)
Upvotes: 0
Reputation: 1138
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]
]
Upvotes: 1