JSFiddle - React, Tailwind, and code Playground
JavaScript
items= [
{
author: "xxx",
difficulty: 3,
dishType: {
guid: "xxxxxxxxxxxxxxxxxxxxxxxx",
label: "Label C",
},
guid: "xxxxxxxxxxxxxxxxxxxxxxx",
id: 10947,
pictures: [{name: "picture",
url: "http://xx.jpg.jpg"
}],
preparationTime: null,
title: "Titre C"
},
{
author: "xxx",
difficulty: 3,
dishType: {
guid: "xxxxxxxxxxxxxxxxxxxxxxxx",
label: "Label A",
},
guid: "xxxxxxxxxxxxxxxxxxxxxxx",
id: 10947,
pictures: [{name: "picture",
url: "http://xx.jpg.jpg"
}],
preparationTime: null,
title: "Titre A"
},
{
author: "xxx",
difficulty: 3,
dishType: {
guid: "xxxxxxxxxxxxxxxxxxxxxxxx",
label: "Label F",
},
guid: "xxxxxxxxxxxxxxxxxxxxxxx",
id: 10947,
pictures: [{name: "picture",
url: "http://xx.jpg.jpg"
}],
preparationTime: null,
title: "Titre F"
}
]
//fcontion de tri sur titre
function sortByTitle(a,b) {
return (a.title > b.title)? 1:-1;
}
//tri de l'array
items.sort(sortByTitle)
//recupération des elements
for (elt in items){ alert('label: '+items[elt].dishType.label +"\nid:" +items[elt].id +"\ntitre"+items[elt].title)}