Well I need to find what does not have in one array for others, I think in an example I can explain better:
I have an array of objects as follows:
NATIVE: [{"_id": "asd12312312", "name": "item 01"}, {"_id": "1123rwerwe", "name": "item 02"}];
But I made an update with one value and added another, so it looked like this:
NEW: [{"_id": "1123rwerwe", "name": "item 02"}, {"name": "item 03"}];
This function needs to return me what was taken in another array, that is, I need this object of the result:
RESULT: [{"_id": "asd12312312", "name": "item 01"}];
Because comparing the "native array" and "new array" it would return what it has in the native and not in the new one, the purpose of this is to know if it removed some item.
Note that the new array exists an item without _id this is given because it added a new item, because who will generate_id is the database itself.
I'm using NODE JS so this function should be basically done inJAVASCRIPT
I have this function that tells me what it has in one and not in the other, it works very well, but for my return case only of what it does not have, it does not work:
const diffObjects = (object, base) => {
function changes(object, base) {
return _.transform(object, function (result, value, key) {
if (!_.isEqual(value, base[key])) {
result[key] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value;
}
});
}
return changes(object, base);
};
Something very important is the performance, because I have a N number of arrays to be sent to this function.
In my example you can see item without _id, in this case the item should be discarded from the logic, need to take into account only the items that have _id
Drawing I have two containers
01 [|||||||||||||]
02 [ |||||||||| |]
In this example I do not need the colored items, I need the items I had in 01 and now do not have in 02, you can see that the last point is colored, that is, it had no 01 and now it has 02, the embroidery is unlike this, what was in the 01 and was deleted in 03.
then the result would be
R [| || ]
That is, it had on 01 and now it does not have on 02
If I use the logic you are talking about it is returning me like this:
RESULT: [{"name": "item 03"}];
nativearr.filter(o => !newarr.some(e => e['_id'] === o['_id']))