I have a function that gets and filters a JSON string to list each chapter of an audio book.
function drawChaperList(book) {
$(".player-book-chapters").html( " ");//clear chapter list
$.each(book.files, function(key, bookChapter){
if(bookChapter.format === "128Kbps MP3"){
console.log(key, bookChapter.track);
var eachBookChapter = $("<li class='chapter'></li>").appendTo('.player-book-chapters');
eachBookChapter.data("track", bookChapter.track).append("<a title='"+bookChapter.title+"' class='bookChapter' href='"+bookChapter.name+"'>"+ bookChapter.title +"</a>");
}
});
}
The result is all the chapters I want but in no particular order. This is my result:
Key, Track #
9 "3"
16 "6"
17 "2"
20 "1"
26 "5"
27 "4"
How can I sort and display the results by the track #? I understand that .sort doesn't work on objects and after bumping my head with this for a bit I hoped someone can help in the right direction.
Thanks