Let's say I have two arrays:
var a = [[1, 10], [2, 10], [3, 10], [4, 10], [5, 10]];
var b = [[1, 20], [3, 20], [4, 20]];
I want to combine these two into a new array:
var c = [[1, 10, 20], [2, 10], [3, 10, 20], [4, 10, 20], [5, 10]];
What's the best way to go about doing this. I'll update my question in a second with what I've tried to do.
var c = [];
for(var i = 0; i < a.length; i++) {
for(var j = 0; j < b.length; j++) {
if(a[i][0] == b[j][0]) {
// Push b value into a
a[i][0].push(b[j][1]);
} else {
// Don't do anything...
}
}
}
c = a; // Useless code here but just wanted to return c
return c;