javascriptjqueryobjectconcatenation

Variable value is not changing according to the variable


So here's the thing. I've declared the following variables to concat my object:

    var newObj = obj[property];
    var fullObj = newObj[id];

Then I'm matching the value of "fullObj" with the value of another obj named "Array". I do it like this:

fullObj  = Array;

Then "fullObj" gets the new value, but the original object, which is something like: "obj.property.id" does not. Any ideas?

EDIT:

This is the function

function updateData(obj, Array, id, property) {
    var newObj = obj[property];
    var fullObj = newObj[id];

    fullObj = Array;
}

The property that I'm sending back is "obj", with all its inner elements (obj.property.id).

As you can see, "fullObj" is the same thing as saying that last object construction. Imagine something like "object.id["0"]. So imagine the value of "Array" is "object.id["1"]. I'm giving "fullObj" that value by matching them both, but the original object won't get it.

Am I being clear enough?


Solution

  • The problem is that you are re-assigning the value for the fullObj variable. You can access the referenced object like that, but you can't change it.

    Anyway, i don't see the point of doing that the way you are doing it. You can assign the value directly like this:

    function updateData(obj, Array, id, property) {
        obj[property][id] = Array;
    }