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...

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
marta
  • 35
  • 2

2 Answers2

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);
});
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
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);
});
The Moisrex
  • 1,857
  • 1
  • 14
  • 16