1

I got this piece of code. Problem is that PUSH wont add anything to the array WORDS or if I try assign value to property. Data in collection that it iterates trough isn't null I tested it and calling other functions from that place in code work for example alert etc.

Thanks for your help.

Here is my piece of code

        var uri = 'GetTickerData';
        var words = [];
        var string;
        $.getJSON(uri)
                .done(function (data) {
                    $.each(data, function (key, item) {
                        words.push('Some text');   //dont work
                        string = 'Another text';   // also dont work
           });
        });
captainsac
  • 2,484
  • 3
  • 27
  • 48
Mitre
  • 273
  • 1
  • 3
  • 11
  • Can you put it on `jsfiddle.net` with the URI so we can test it out – Ali Gajani May 22 '15 at 11:12
  • 2
    possible duplicate of [How to return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – antyrat May 22 '15 at 11:13
  • well i dont have problem with data that it returns , if i use for example $('
  • ', { text: formatItem(item) }).appendTo($('#data')); it will show returned data properly everytime so thats not problem
  • – Mitre May 22 '15 at 11:14
  • 2
    @Mitre `getJSON` is asynchronous call. So you can access your filled in `words` array only inside `done` callback. – antyrat May 22 '15 at 11:16
  • @Mitre How do you know it doesnot work? Where are you checking whats inside `words` and `string`? – Zee May 22 '15 at 11:22
  • Well i got piece of code that displays what is inside of WORDS. I also got console log with that from collection and its ok. But i think Antyrat is right and i just cant manipulate with that array in there. – Mitre May 22 '15 at 11:27