I am using the below code to access the SoundCloud playlists using Javascript. so the Soundcloud API
returns a JSON document of the entire playlist details which also has 52 tracks within it.
So I am assigning track_id[] global variable all the track IDs in it. But the value of it is valid inside the function.
But when I try to use the value outside the function it says "undefined". So I want to use the track ID outside the function to play the track related to that track ID. so please help me do it.
var i = 843490127;
var track_id = [];
SC.get('/playlists/' + i).then(function(playlist) {
playlist.tracks.forEach(function(track, index) {
track_id[index] = track.id;
});
console.log("value [1]" + track_id[1]); //value valid
});
console.log("value [1]" + track_id[1]); //undefined