如何检查JavaScript对象是否彼此不同

如何检查JavaScript对象是否彼此不同,javascript,Javascript,我正在尝试比较两个对象数组,目前正在使用Array.length()进行比较,根据我试图实现的目标,这似乎不是正确的方法 我有两个对象数组: const array1 = [ { "book_id": 285, "status": "Borrowed", "attributes": [ { "name": "To Kill a Mo

我正在尝试比较两个对象数组,目前正在使用
Array.length()
进行比较,根据我试图实现的目标,这似乎不是正确的方法

我有两个对象数组:

const array1 = [
  {
    "book_id": 285,
    "status": "Borrowed",
    "attributes": [
      {
        "name": "To Kill a Mockingbird",
        "description": "Published in 1960, this timeless classic explores human behaviour and the collective conscience of The Deep South in the early 20th century. Humour entwines the delicate strands of prejudice, hatred, hypocrisy, love and innocence to create one of the best novels ever written.",
        "borrowed_by": "John"
      }
    ]
  },
  {
    "book_id": 284,
    "status": "Borrowed",
    "attributes": [
      {
        "book_name": "ATTRIBSAMP 1",
        "description": "Although 1984 has passed us by, George Orwell’s dystopian, totalitarian world of control, fear and lies has never been more relevant. Delve into the life of Winston Smith as he struggles with his developing human nature in a world where individuality, freewill and love are forbidden.",
        "borrowed_by": "Bob"
      }
    ]
  }
]
VS

基本上,我想检查两者之间是否有变化,即借用的
和/或
状态
,我现在知道
array1.length
将等于
array2.length
,因为数组长度始终等于2。有没有更简单或更好的方法来检查这一点

预期输出,我想调用函数
callFunction1()

我目前有:

if(array1.length !== array2.length){
    callFunction1();
} else {
    null;
}

为了结束这个问题,我选择了Lodash的
。.isEqual
进行比较

if(!_.isEqual(array1, array2){
    callFunction1();
} else {
    null;
}

为了结束这个问题,我选择了Lodash的
。.isEqual
进行比较

if(!_.isEqual(array1, array2){
    callFunction1();
} else {
    null;
}

预期的产出是多少?你能把它也加上吗?编辑以添加我想做的。这里的array1.length和array2.length都是一样的,不是吗?也就是说,都是长度2?你总是有空的存在called@MayankMehtani是的,这就是我要问的,我如何“更好地”比较它们以获得函数调用:)您可能想做一个深入的比较。检查此项,以便发布预期输出?你能把它也加上吗?编辑以添加我想做的。这里的array1.length和array2.length都是一样的,不是吗?也就是说,都是长度2?你总是有空的存在called@MayankMehtani是的,这就是我要问的,我如何“更好地”比较它们以获得函数调用:)您可能想做一个深入的比较。检查这封邮件
if(!_.isEqual(array1, array2){
    callFunction1();
} else {
    null;
}