I tried to sort an object that contains other objects and arrays in it E.g
let object = {
'2573': {
results: [
{
"rooms": {
"price": 1500
},
},
{
"rooms": {
"price": 1700
},
}
],
},
'2574': {
results: [
{
"rooms": {
"price": 1800
},
},
{
"rooms": {
"price": 1900
},
}
],
},
'2575': {
results: [
{
"rooms": {
"price": 1850
},
},
{
"rooms": {
"price": 1200
},
}
],
}
}
I don't really understand how I could sort this object In the first phase, I should clearly access the first key, after accessing the rooms array and then filtering according to the prices found in each rooms object Is this possible?
I tried something like this
object.sort((a, b) => Object.keys(a)[0] - Object.keys(b)[0]);
But I clearly do not reach the necessary objects to be able to do this filtering
So is it possible to sort by the prices of all the rooms in the object?
results ascending sort
let object = {
'2574': {
results: [
{
"rooms": {
"price": 1200
},
{
"rooms": {
"price": 1850
},
}
}
],
},
'2573': {
results: [
{
"rooms": {
"price": 1500
},
},
{
"rooms": {
"price": 1700
},
}
],
},
'2574': {
results: [
{
"rooms": {
"price": 1800
},
},
{
"rooms": {
"price": 1900
},
}
],
}
}