Right now my output renders on the page in the same order reflected in the raw JSON file. I'm hoping to figure out how to sort by a property in each item.
Examples would include sorting alphabetically by name
desc and asc - or - by index
asc or desc.
Any help would be much appreciated!
menu.json
{ "menuItems": [
{
"index": 12432564,
"parentCategory": "Espresso",
"name": "Caffè Americano",
"photos": {
"squarePhoto": "photo.jpg"
}
}, {
"index": 3546754,
"parentCategory": "Espresso",
"name": "Caffè Latte",
"photos": {
"squarePhoto": "photo.jpg"
}
}...
master.js
$.getJSON('menu.json', function(drinks) {
var output = "";
for (var i in drinks.menuItems) {
output += "<li>" + drinks.menuItems[i].name + "</li>";
}
//output+="</ul>";
document.getElementById("demo").innerHTML=output;
});