jQuery/JavaScript JSON object comparison

后端 未结 5 1402
执笔经年
执笔经年 2020-12-10 06:08

Is it possible to compare 2 sets of json objects for a difference? What I have is a script thats polling for JSON object via jquery $post(). What I want to do is take the ob

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 06:29

    One potential solution could be to use jQuery's extend. As long as the objects have the same properties, that would work out nicely.

    var newJSON = $.extend({},oldJSON,serverData);
    

    Then you would have preserved the old object, and created a new object with any properties from the old object if they aren't present in the new object and overwritten any existing properties with the properties from the new data from the server.

提交回复
热议问题