Garmaine Staff asked 1 year ago
This question already has answers here:”>How to get the difference between two arrays of objects in JavaScript (13 answers)
Closed 5 hours ago.

This is driving me crazy.

I'm trying to do a get an array that is the difference between two arrays containing json objects.

I can do this easily with arrays of primitive values, by using sets. I mainly come from a Java background not JavaScript and this seems annoyingly difficult.

const available = [{time:1, chargable: true}, {time:2, chargable: false}, {time:3, chargable: true},{time:4, chargable: true}];
const booked = [{time:2, chargable: false}, {time:3, chargable: false}, {time:4, chargable: false}];

const remainingAvailable = findRemainingAvailable(available, booked)

I want remainingAvailable to contain: [{time:1, chargable: true}]

How do I do that (ideally using funky functions like filter etc)?