I have a big problem, I already researched in several places and I did not find the solution I hope you can help me ... My goal is to create a function in JS that will get an array as a base, which I will call here as " A " its structure is this:
var A = {
a1: {
c1: 50,
c2: 50,
},
b1: {
d1: 0,
d2: [1 => "hello"],
d3: [2 => "world"],
}
};
The function will get another array, which I'll call " B ", it follows the structure of it:
var B = {
a1: {
c1: 1,
c2: 125,
},
};
After the array " B " pass through the function it should "exit" with the structure identical to " A " and with the missing values in " B "identical to" A ", ie:
Array " B " after passing the function:
var B = {
a1: { /* índice que já existia no array "B" */
c1: 1, /* índice e valor que já existia no array "B" */
c2: 125, /* índice e valor que já existia no array "B" */
},
b1: { /* índice que NÂO existia no array "B" e como o array "A" é a base foi criado esse índice no array "B" */
d1: 0, /* índice e valor que não existia no array "B", é a mesma história do b1 aqui em cima */
d2: [1 => "hello"], /* mesmo caso dos outros dois acima */
d3: [2 => "world"], /* mesmo caso dos outros três acima */
}
};
Let's say that's fine, my big question is, I have the array " A " as a basis, when I want to modify the " A structure" add one more level to it as in the example:
var A2 = {
a1: {
c1: 50,
c2: 50,
},
b1: {
d1: 0,
d2: [e1 => "hello"],
d3: [
f2 => "world",
f3 => [
g1 => "nova",
g2 => "camada"
]
],
}
};
The way I figured this script would go wrong if I did this and it's obvious that I do not want this to happen, what I really want is for the array " B " to pass through function, also receive the new layer ...
I've already started to do this code, but I can not finish it because of this damn doubt. Code that I have already developed link