0
votes

I have 2 JSON object arrays in my java script and i am trying to figure out a way to output the differences (if any) between the 2.

for example, here is one of the arrays :

   [{  
      "id":1,
      "colour":"BLACK",
      "size":"SML",
      "qty":1,
      "sml":"1"
   }]

and here is another :

        [{  
      "id":1,
      "colour":"BLACK",
      "size":"SML",
      "qty":1,
      "sml":"5",
      "lrg":"1"
       },
       {  
      "id":2,
      "colour":"BLACK",
      "size":"SML",
      "qty":1,
      "sml":"1"
       }]

In the above example i would print to the user that one product has been added, the id 1 product has had sml changed to 5 and lrg added. Is there a way to compare the 2 arrays and get the values that are changed / added?

1
please post the code you have trieduser93
How do you know that a new item has been added? Are you comparing using id only?31piy
I know somethings been added if the length of array 2 is larger than array 1Gaz Smith

1 Answers

1
votes

There is a library for getting the structural differences between two objects https://github.com/flitbit/diff