0

I'm trying to compare 2 large JavaScript Objects with almost ~200 keys each, the keys are unordered, and have different values for each of the JavaScript Objects, but I only care about the keys if they both have the same set of keys that function would still return true even if they're in different order

I tried the following code but didn't work

var cp = function (nl,en) {
let x= Object.keys(nl);
let y= Object.keys(en);
for (xel in x){
    if (!y[xel]){
        console.log("missing key en ", xel);
    }
}}

Example:

{"key1": "val", "key2": "sdsfaf"}
{"Key2": "val", "key1": "vsdsdsd"}
This should return true
{"key1": "val", "key2": "sdsfaf"}
{"Key2": "val"}
This shouldn't
crashmstr
  • 28,043
  • 9
  • 61
  • 79
user1712638
  • 201
  • 2
  • 8
  • 22

1 Answers1

0

Grab sets of the objects' keys with new Set(Object.keys(a)) and new Set(Object.keys(b)).

Then compare them with eg. comparing ECMA6 sets for equality

AKX
  • 152,115
  • 15
  • 115
  • 172