Compare two objects properties in JS

后端 未结 5 1864
面向向阳花
面向向阳花 2021-01-21 13:56

I need to compare two objects, and find out what properties are missing. The objects are fairly big, with several levels.

I will give short example of the type of object

5条回答
  •  借酒劲吻你
    2021-01-21 14:48

    How about use JSON.stringify to convert object to string, then do the string comparison:

    JSON.stringify(UC) === JSON.stringify(UCToBeCompared)
    

    By using this method, you have to make sure the objects don't have circular reference, otherwise JSON.stringify would throw an exception

提交回复
热议问题