I am at a loss for the best way to do this. I have 3 Arrays of Objects
arr1 = [
{Client ID:"1", Client Name:"ABC", D1:"some data", D2:"more data"},
{Client ID:"2", Client Name:"DEF", D1:"some data", D2:"more data"},
{Client ID:"3", Client Name:"GHI", D1:"some data", D2:"more data"}
]
arr2 = [
{Client ID:"1", Client Name:"ABC", D3:"and more data", D4:"more more data"},
{Client ID:"2", Client Name:"DEF", D3:"and more data", D4:"more more data"},
{Client ID:"3", Client Name:"GHI", D3:"and more data", D4:"more more data"}
]
arr3 = [
{Client ID:"1", Client Name:"ABC", D5:"other data", D6:"extra Data"},
{Client ID:"2", Client Name:"DEF", D5:"other data", D6:"extra Data"},
{Client ID:"3", Client Name:"GHI", D5:"other data", D6:"extra Data"}
]
I want to combine it into
newArr = [
{Client ID:"1", Client Name:"ABC", D1:"some data", D2:"more data", D3:"and more data", D4:"more more data", D5:"other data", D6:"extra Data"},
{Client ID:"2", Client Name:"DEF", D1:"some data", D2:"more data", D3:"and more data", D4:"more more data", D5:"other data", D6:"extra Data"},
{Client ID:"3", Client Name:"GHI", D1:"some data", D2:"more data", D3:"and more data", D4:"more more data", D5:"other data", D6:"extra Data"}
]
Another catch is, that all 3 Arrays won't always have data in it! Sometimes I May only combine arr2 and arr3 or arr1 and arr3 or arr1 and arr2.
Thanks!
if(arr1[0].length > 0) { for(var i = 0; i < arr1.length; ) { if(newArr.length > 0) { for(var j = 0; j < newArr.length; j++) { if(arr1[i]["Client ID"] == newArr[j]["Client ID"]) { if(arr[i].length != newArr[j].length) { for(var g = 2; g < arrData[i].length; g++) { newArr.push(arr1[i][g]); } } } else { newArr.push(arr1[i]); } } i++; } else { newArr.push(arr1[i]); } } }