0

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?

user93
  • 1,866
  • 5
  • 26
  • 45
Gaz Smith
  • 1,100
  • 1
  • 16
  • 30

1 Answers1

1

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

Ariel Henryson
  • 1,316
  • 1
  • 10
  • 13