Ich muss zwei Arrays vergleichen und Elemente zu einem Array schieben, wenn keines der Objekte in diesem Array mit dem zweiten Array übereinstimmt.Benötigen Sie Hilfe beim Durchlaufen von 2 verschachtelten Arrays in Javascript/AngularJS und tun Vergleich
Bitte meine JSON die Sie interessieren könnten:
Array 1:
"[{
"carrierName":"A",
"id":7,
"active":true
"subList":[{
"active":false,
"carrierServiceId":"19",
"locationPrimaryContactName":"ABC 4",
"locationPrimaryContactNumber":"1111",
"locationStateCode":"NJ",
"locationZipcode":"56324",
"name":"A 4"}
,
{
"active":true,
"carrierServiceId":"20",
"locationPrimaryContactName":"ABC 1",
"locationPrimaryContactNumber":"1111",
"locationStateCode":"NJ",
"locationZipcode":"56324",
"name":"A 1"
},
{
"active":true,
"carrierServiceId":"21",
"locationPrimaryContactName":"ABC 2",
"locationPrimaryContactNumber":"1111",
"locationStateCode":"NJ",
"locationZipcode":"56324",
"name":"A 2"},
{
"active":true,
"carrierServiceId":"22",
"id":1001,
"locationPrimaryContactName":"ABC 3",
"locationPrimaryContactNumber":"1111",
"locationStateCode":"NJ",
"locationZipcode":"56324",
"name":"A 3"
}
]
}
]"
Array 2:
"[{"subList":[
{
"active":true,
"code":"20",
"id":0,
"locationPrimaryContactName":"ABC 1",
"locationPrimaryContactNumber":"1111",
"name":"A 1",
},
{
"active":true,
"code":"21",
"id":0,
"locationPrimaryContactName":"ABC 2",
"locationPrimaryContactNumber":"1111",
"name":"A 2",
},
{
"active":true,
"code":"22",
"id":0,
"locationPrimaryContactName":"ABC 3",
"locationPrimaryContactNumber":"1111",
"name":"A 3",
},
{
"active":true,
"code":"19",
"id":0,
"locationPrimaryContactName":"ABC 4",
"locationPrimaryContactNumber":"1111",
"name":"A 4",
}
],
"active":false,
"id":7,
"name":"A",
},
{
"subList":[
{
"active":true,
"code":"7",
"id":0,
"locationPrimaryContactName":"DEF 1",
"locationPrimaryContactNumber":"2222",
"name":"B 1",
},
{
"active":true,
"code":"8",
"id":0,
"locationPrimaryContactName":"DEF 2",
"locationPrimaryContactNumber":"2222",
"name":"B 2",
},
{
"active":true,
"code":"9",
"id":0,
"locationPrimaryContactName":"DEF 3",
"locationPrimaryContactNumber":"2222",
"name":"B 3",
}
],
"active":false,
"id":8,
"name":"B",
},
{
"subList":[
{
"active":true,
"code":"10",
"locationPrimaryContactName":"GHI 1",
"locationPrimaryContactNumber":"3333",
"name":"C 1",
}
],
"active":false,
"id":9,
"name":"C",
},
{
"subList":[
],
"active":false,
"id":10,
"name":"D",
}
]"
Hier, wenn Sie sehen, die gemeinsamen Felder sind id, sublist.carrierServiceId in Array 1 & subList.code in Array 2. Meine Anforderung ist, dass ich Array 1 und Array 2 durchlaufen muss und die Elemente von Array 2 zu Array 1 hinzufügen, Wenn es nicht existiert, Array 1. Wenn Sie hinzufügen, müssen Sie das Array "subList" auch für eine bestimmte "id" in Array 2 überprüfen und wenn diese in Array 1 vorhanden sind, sollten sie auch nicht hinzugefügt werden.
Fragen Sie einen Experten zu diesem Thema. Bitte lassen Sie mich wissen, wenn die Abfrage mehr Klarheit benötigt.
bitte das gewünschte Ergebnis hinzuzufügen und den Code, den Sie versucht. –
zum Beispiel, was soll mit 'code = 7' geschehen? –