I'm trying clone a json object inside a function wanting to access the object outside the function. But when function is done, the object still seems to be undefined. Seems like it's not the same variable?
var jsonUserObj;
$.getJSON("user.json", function(content){
jsonUserObj = $.parseJSON(JSON.stringify(content));
console.log(content);
console.log(jsonUserObj); //looks fine!
});
console.log(jsonUserObj); //undefined
inside the callback function it contains all the data, but it does not remain outside of it. How to make it assessible globally?
jsonUserObject!==jsonUserObjThat's the reason for theundefined. The asynchronous call however, will cause it not to have the new values when you view it immediately following thegetJSON()call.