there is no result my javascript array WHY? -


this question has answer here:

i push data array can see in array out of function there no data in array why ??

function keywordsearch() {

        var musicids = [];         gapi.client.setapikey('aizasyb2o-w22osjvskphaysk_zxx7fsthm0mhe');         gapi.client.load('youtube', 'v3', function () {             idlist = '';               var q = $('#queryserach').val();             $("#result").empty();             var request = gapi.client.youtube.search.list({                 q: q,                 part: 'snippet',                 maxresults: 3,              });              request.execute(function (response) {                  (var = 0; < response.items.length; i++) {                      var musicid2 = response.items[i].id.videoid;                      musicids.push(musicid2);                     // push data array can see in array  out of function there no data in array why ?? ------                      var pid = '#myplayerid';                     var ratio = '4/3';                  }              });          });         alert(musicids[1]); // here musicid[1] return undefined 

}

ajax calls asynchronous, have alert inside response function api called. in case inside request.execute(function (response) {

request.execute(function (response) {              (var = 0; < response.items.length; i++) {                  var musicid2 = response.items[i].id.videoid;                  musicids.push(musicid2);                  var pid = '#myplayerid';                 var ratio = '4/3';              }              alert(musicids[1]); } 

more info here


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -