我需要合并这个:
arrays
{ "Components": { "ID": 119, "Name": "Fire", }
, "Company": { "ID": 6, "Name": "Leadw", }
, "InsuranceType": { "ID": 3, "Name": "Motor" }
, "ID": 119
, "Percentage": 5
}
, { "Components": { "ID": 120, "Name": "Flood", }
, "Company": { "ID": 6, "Name": "Leadw", }
, "InsuranceType": { "ID": 3, "Name": "Motor" }
, "ID": 120
, "Percentage": 2 }
, { "Components": { "ID": 121, "Name": "Theft", }
, "Company": { "ID": 6, "Name": "Leadw", }
, "InsuranceType": { "ID": 3, "Name": "Motor" }
, "ID": 121
, "Percentage": 4
}
答案 0 :(得分:0)
在你的问题中,你只带了一个阵列...... 如果你想象有两个这样的阵列...... 然后像这样:
var arrays1 = [{
"Components": {
"ID": 119,
"Name":"Fire",
},
"Company": {
"ID": 6,
"Name": "Leadw",
},
"InsuranceType": {
"ID": 3,
"Name": "Motor"
},
"ID": 119,
"Percentage": 5
},
{
"Components": {
"ID": 120,
"Name":"Flood",
},
"Company": {
"ID": 6,
"Name":"Leadw",
},
"InsuranceType": {
"ID": 3,
"Name": "Motor"
},
"ID": 120,
"Percentage": 2
},
{
"Components": {
"ID": 121,
"Name": "Theft",
},
"Company": {
"ID": 6,
"Name": "Leadw",
},
"InsuranceType": {
"ID": 3,
"Name": "Motor"
},
"ID": 121,
"Percentage": 4
}];
var arrays2 = [{
"Components": {
"ID": 125,
"Name":"Fire1",
},
"Company": {
"ID": 6,
"Name": "Leadw1",
},
"InsuranceType": {
"ID": 3,
"Name": "Motor1"
},
"ID": 125,
"Percentage": 7
},
{
"Components": {
"ID": 128,
"Name":"Flood",
},
"Company": {
"ID": 6,
"Name":"Leadw",
},
"InsuranceType": {
"ID": 3,
"Name": "Moto5"
},
"ID": 128,
"Percentage": 2
}];
var merge_arr=[];
for(var key1 in arrays1){
merge_arr.push(arrays1[key1]);
}
for(var key2 in arrays2){
merge_arr.push(arrays2[key2]);
}
//for test
for(var key_ma in merge_arr){
console.log(merge_arr[key_ma], 'Components ID =>'+merge_arr[key_ma].Components.ID);
}