0
使用JavaScript實現兩個對象的深度是comapre,如果true不等於等於返回值,則返回false。第一個參數與原始對象相比較,第二個參數用於比較目標對象,該對象屬性存在於值中只存在,該屬性不存在於原始對象中,如果該對象,則會直接返回false。這裏有些例子。兩個對象之間的部分深度比較
const object = {
id: 1,
name: 'test',
product: {
id: 1,
name: 'product'
},
updatedAt: 'now'
};
const objectA = {
name: 'test',
product: {
name: 'product'
}
};
const objectB = {
name: 'test',
product: {
name: 'anotherProduct'
}
};
compare(object, objectA) // return true
compare(object, objectB) // return false