I have two JavaScript literal objects below:
var obj1 = {
3a5f5c70-58ef-4e4b-8fe0-a271ea2b4f11: true,
9e185ad9-0816-4c5b-ab97-a6c0103d6c22: true,
-K5F-v9lDvZPgDuVhMi3: true,
-K5F-wzH1J01CFXZ9r2c: true,
-K5F-x6H4NXdlwXlolQE: true}
var obj2 = {
-K5F-v9lDvZPgDuVhMi3: true,
-K5F-wzH1J01CFXZ9r2c: true
}
I want to find the difference between them so that when I call:
var result = findDifference(obj1, obj2);
So that the result
variable would be
result = {
3a5f5c70-58ef-4e4b-8fe0-a271ea2b4f11: true,
9e185ad9-0816-4c5b-ab97-a6c0103d6c22: true,
-K5F-x6H4NXdlwXlolQE: true
}
I could loop both objects and compare their keys for non-equality or probably convert to then array type first. But I am curious if there is an existing library that is more efficient when the objects grow larger. I have looked at underscore but cant seem to find one that meet my need.
jsfiddle: https://jsfiddle.net/1y3a72rn/