The code that I have works, but the order of the objects isn't correct.
That's what the JSON looks like:
https://i.gyazo.com/102efe767cb0a3d8be8a4a57b6b4560e.png
In the data, in array element 11 the num property has the value 420, the channel number.
What I want to do is iterate over the loop according to the channel numbers (num), not by the order of available_channels as they appear in the JSON. How do I change the loop so that it iterates by channel number?
http://jsfiddle.net/gnpj5csk/231/
var yql_url = 'https://query.yahooapis.com/v1/public/yql';
var url = 'http://***/***.php?username=***&password=***';
$.ajax({
'url': yql_url,
//remove this line later
'data': {
'q': 'SELECT * FROM json WHERE url="'+url+'"',
'format': 'json',
'jsonCompat': 'new',
},
'dataType': 'json',
'success': function(response){
console.log(response);
var res = response.query.results.json;
var keys = Object.keys(res.available_channels);
for(var i =0;i< keys.length;i++){
var num = res.available_channels[keys[i]].num;
$('#channellist').append(num+"<br>");
}
}
});
More info:
array 46 - channel number 1:
https://i.gyazo.com/a575219039b8e76c6dc4f7bdc3b99627.png array 26 - channel number 2:
https://i.gyazo.com/3f765e3a73f61d96080cf8fb74de2ae3.png
Order should be..
46 , 26, 47, 27, 48, 24 by the 'num' array order
Right now: 396, 384, 395, 390, 386 (available_channels order)
48come before26?