Я использую lodash для сравнения двух массивов объектов с функцией DifferentWith (isEqual).
Вот мои два массива:
array1
[
{
"id":"28884",
"designation":"French fries",
"description":"French fries",
"prices":[
{
"price":0,
"vat":2821
}
]
},
{
"id":"28885",
"designation":"Potatoes",
"description":"Potatoes",
"prices":[
{
"price":0,
"vat":2821
}
]
}
]
array2
[
{
"id":"28884",
"designation":"French fries",
"description":"French fries",
"prices":[
{
"price":0,
"vat":2821
}
]
},
{
"id":"28885",
"designation":"Potatoes",
"description":"Potatoes",
"prices":[
{
"price":0,
"vat":2821
}
]
},
{
"id":"30157",
"designation":"new item",
"description":null,
"prices":[
{
"price":500,
"vat":2821
}
]
}
]
Вот что я сделал, но это не работает:
const toAdd = _.differenceWith(array1, array2, _.isEqual);
const toRemove = _.differenceWith(array2, array1, _.isEqual);
Как получить удаленные элементы? Кроме того, как я могу получить новые элементы, удаленные элементы с помощью lodash? Спасибо!