3
$.getJSON("sluzba.json", function(result){
    array = $.each(result, function(value){
        return value;
    });
  tableMaker(array);
});

This is my code, I want to have an access to the array from outside the scope of this function.

Is it possible?

Please help...

2

2 Answers 2

1

Yes, it is possible. You can using a callback method.

function myFunction(callback){
    $.getJSON("sluzba.json", function(result){
    array = $.each(result, function(value){
       return value;
    });
    callback(array);
    tableMaker(array);
    });
}
myFunction(function(myArray){
   console.log(myArray);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, callback helped! I've tried it before, but put it in wrong place
0

the easiest way is to just use a global variable.

var array;
$.getJSON("sluzba.json", function(result){
    array = $.each(result, function(value){
        return value;
    });
  tableMaker(array);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.