Compare two arrays and update them with new values, preserving existing objects using javascript. Does not work to delete objects.

This is the next question for Compare two arrays and update them with new values, preserving existing objects using javascript , which was added by @Siderite Zackwehdex

Please check this plunker . I get the deleted object in the changedArray1.Is file there is an opportunity to fix this. It works great for other changes, such as adding, updating, but not deleting.

One of the possibilities that I tried to implement is to add an additional object, i.e. "removedIds":[23] , which contains the remote identifier as an array at each level of objects and identifies them during the evaluation process .. but did not find the right soul

Sample data:

 var parentArray1=[ { "id": 1, "name": "test", "context": [ { "operationalContextId": 1.1, "valueChainEntityDetails": [ { "valuChainEntityId": 3, "name": "test", "context": [ { "id": 3.1, "name": "test 3.1", "activityDetails": [ { "activityId": 22, "name": "test 3.1" }, { //trying to remove activity id 23 "activityId": 23, "name": "changed test 23" } ] } ] } ] } ] } ] var changedArray1=[ { "id": 1, "name": "test2", "context": [ { "operationalContextId": 1.1, "valueChainEntityDetails": [ { "valuChainEntityId": 3, "name": "changed test3", "context": [ { "id": 3.1, "name": "test 3.1", "removedIds":[23] , "activityDetails": [ //activity id 23 is removed in this JSON but reflecting in parentArray1 { "activityId": 22, "name": "changed test 3.1" } ] } ] } ] } ] } ] 
0
source share

Source: https://habr.com/ru/post/1245474/


All Articles