I got two JavaScript
objects
. I want to compare both objects
to one another. If object 1
has a key
which is missing in object 2
add this key
to object 2
.
But this must also be the case if object 2
has a key
which is missing in object 1
.
So for example, object 1
looks like this.
var object_1 = {
"Address": "Address",
"AccessDeniedText": "You do not have access to the page you requested.<br>Use the navigation menu on the left to select a page you want to open.",
"Basket": "Shopping cart",
"BasketVAT": "VAT {0}"
...
};
object 2
looks like this.
var object_2 = {
"Address": "Address",
"Basket": "Shopping cart",
...
};
In object 2
the key
AccessDeniedText and BasketVAT are missing.
Expected result
What i now want is to have an new object
, lets say object 3
that would now output the following.
var object_3 = {
"Address": "Address",
"AccessDeniedText": "", // I can fill this missing text
"Basket": "Shopping cart",
"BasketVAT": "" // I can fill this missing text
}
I tried to use $.each()
and for(key in object)
. However, this made my whole browser crash. Not so wierd, because each object
has more then a 1000 rows.
I also tried to awnser of this question: Javascript: compare two objects, and get key-value pair It didn't work for me.
Is there a simple way to do it? Without my browser crashing of the heavy payload? I dont care using jQuery
.