I tried whith no success to sort an array of multiple objects of objects.
Here my database :
var jsonDatas = [
{
"type": "Voiture",
"items": [
{
"name": "Fiat Punto",
"description": "Je suis une voiture",
"price": 10000,
"quantity": 2,
},
{
"name": "Porsche 911",
"description": "Je suis une belle voiture",
"price": 80000,
"quantity": 0,
},
],
},
{
"type": "Maison",
"items": [
{
"name": "Villa sur la plage",
"description": "Quelle belle vue",
"price": 870000,
"quantity": 1,
}, {
"name": "Maison à la campagne",
"description": "Vive le calme",
"price": 170000,
"quantity": 3,
}
],
}
I want to sort items by name (obtain Fiat, Maison, Porsche, Villa) , problem is the type, because each time, it sort first the type then the products by type.
I tried this for example :
function sortDatasASC(){
database.forEach(element =>
element.items.sort((a, b) => (a.name > b.name) ? 1 : -1)),
catalogFiltered();
If you have any ideas!?
Thanks in advance.