JavaScript: how do i clear a global JSON variable assigned to a local one?

Viewed 25

Is there a way to clear a global declared JSON that have been assigned to a local variable?

I already know that using something like delete json[key] will work, but I'm looking for a more comprehensive way to reset the global JSON.

I'll give you some simple code:

let jsonA = { a:1,b:2 };
let jsonB = { c:3,d:4 };

function func(){
    let localVariable = jsonA;
    if(condition)
        localVariable = jsonB;
    
    // here I want to reset the global JSON, depending on which one has been assigned to the local variable

    localVariable = {}; // this won't work, it will only reset the local variable but not the global one
}
0 Answers
Related