Compare arrays of objects, optimal way

前端 未结 3 624
醉酒成梦
醉酒成梦 2020-12-18 07:17

I have two arrays. In each array I have objects with lots of properties but no methods. I need to see if array 1 is equal with array 2.

One way to do that would be t

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 07:50

    JQuery has a function called jQuery.param() which serializes objects

    You can compare objects or arrays of objects like so,

    $.param( originalObj ) == $.param( modifiedObj )
    

    It's very powerful in conjuction with jQuery.extend() which can be used to clone objects

提交回复
热议问题