JSFiddle - React, Tailwind, and code Playground

JavaScript

console.clear();

var a = [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}];

var b = [{id: 1}, {id: 2}, {id: 3}, {id: 5}];

var c = [];

// I want c to contain only {id:4} - the one element in a but not in b
onlyInA = a.filter(function(current) {
    return b.filter(function(currentB) {
        return currentB.id == current.id;
    }).length == 0;
});

onlyInB = b.filter(function(current) {
    return a.filter(function(currentA) {
        return currentA.id == current.id;
    }).length == 0;
});

c = onlyInA.concat(onlyInB);
console.log("C is now", c);