JavaScript: Assign an object to another object

I’m trying to assign the local var UgcItems to uploadedItems but when I try to return the value I get undefined. If I put the console.log inside of the .getJSON then I get the appropriate value. The problem with that is that the scope is inside of the function. What can I do to get the JSON out of the function?

$  (function(){
    var uploadedItems;
    $  .getJSON("GetExistingUgcItems?workItemId=1", function (UgcItems) {
        uploadedItems = fromJSON(toJSON(UgcItems));
    });

    console.log(uploadedItems);
});

Thank you,

Aaron

newest questions tagged jquery – Stack Overflow

About Admin