javascript - Merge two multidimensional arrays, but cant duplicate using datetime -


i wish merge 2 arrays one, cant duplicate using datetime, cant merge 2 results both arrays same datetime.

  • in each array, datetime never repeated.
  • both arrays have same structure, same exact positions.
  • each array have +60 sub arrays.

example:

array1 = [[a,b,0000-00-00 00:00],[c,d,0000-00-00 00:59],[e,f,0000-00-00 00:10]]; array2 = [[z,x,0000-00-00 00:00],[h,s,0000-00-00 00:49],[e,f,0000-00-00 00:20]];   array12 = [[a,b,0000-00-00 00:00],[c,d,0000-00-00 00:59],[e,f,0000-00-00 00:10],[h,s,0000-00-00 00:49],[e,f,0000-00-00 00:20]]; 

how can make work? tried lot of functions, cant working.

thanks.

if i'm correct trying merge arrays based in timestamps. try out fiddle

var array1 = [     ['a', 'b', '0000-00-00 00:00'],     ['c', 'd', '0000-00-00 00:59'],     ['e', 'f', '0000-00-00 00:10'] ]; var array2 = [     ['z', 'x', '0000-00-00 00:00'],     ['h', 's', '0000-00-00 00:49'],     ['e', 'f', '0000-00-00 00:20'] ];  function mergearrays(arr1, arr2) {     var merger = {};      (var = 0; < arr1.length; i++) {         merger[arr1[i][2]] = [arr1[i][0], arr1[i][1], arr1[i][2]];     }      (var = 0; < arr2.length; i++) {         if (!(arr2[i][2] in merger)) {             merger[arr2[i][2]] = [arr2[i][0], arr2[i][1], arr2[i][2]];         }     }      var output = [];     (var key in merger) {         output.push(merger[key]);     }     return output; }  var result = mergearrays(array1, array2); console.log(result); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -