0

I suppose that is very basic question, but I don't really understand, why do I get different results. Inside function(data) the map fills and show as filled. When I get out, it flushes.What is wrong? Strangely, first thing that I receive in my Chrome JS Console is console.log(map) from inner function, not the last one, so they seem to be printed out in reverse order.

var map = {};

var deps = $.get("#####", function (data) {

    $.each(data, function (tag, data) {
        $.each(data, function (param, info) {
            if (param == 'name')
                map[tag] = param;
        });
    });
    console.log(map)
});

console.log(map)
Mathias
  • 5,642
  • 2
  • 31
  • 46
vladfau
  • 1,003
  • 11
  • 22

1 Answers1

5

The last line, console.log(map) executes before the callback function. When it executes, the request hasn't finished yet, so map is still empty.

guest
  • 6,450
  • 30
  • 44