I'm struggling to combine two arrays in a specific manner and can't quite figure out the correct syntax to achieve this.
primaryData = [1,2]
secondaryData = [3,4]
label = [label1, label2]
Currently, I have this working
data = $.map(labels, function(v, i) {
return [[" " + v, " " + primaryData[i], " " + secondaryData[i]]] ;
});
This produces the output:
[["label1", "1"], ["label2", "2"]]
Resulting in two arrays within an array.
However, my desired outcome is:
[["label1", "1"], ["label2", "2"], ["label1", "3"], ["label2", "4"]]
In essence, repeating the same process twice with "labels" and then incorporating numbers from different sources.
I've attempted the following:
data = $.map(labels, function(v, i) {
return [[" " + v, " " + primaryData[i]], [" " + v, " " + secondaryData[i]]];
});
However, this yields:
[["label1", "1"], ["label1", "3"], ["label2", "2"], ["label2", "4"]]
It appears that the arrays are merging in a concatenative manner. Using + instead of comma separation results in 2 objects within an array rather than 2 arrays within an array.