Object value Ordering
type Month = { [yyyymmStr: string]: MonthlyDateProps }
const months = {
"2025-01" : {...values},
"2025-05" : {...values},
}
months = {...months , {["2024-12"]: {...values} }
// drawing
Object.keys(months).map((key, index) => {
const values = months[key];
return <div></div>)}
// result
{
"2025-01" : {...values},
"2025-05" : {...values},
"2024-12" : {...values},
}
type Month = Map<string, MonthlyDateProps>
const map = new Map({
"2025-01" : {...values},
"2025-05" : {...values},
})
map.set("2024-12", {...values});
// for the orderging
const orderedTupleArr = Array.from(map.entries()).sort(
// prevValue and currentValue are tuple [key,value]
([yyyymmAskeyPrev, value1] , [yyyymmAskeyCurr,value2]) => {
return yyyymmAskeyPrev.localeCompare(yyyymmAskeyCurr);
})
const orderedMap = new Map(orderedTupleArr) ;
// drawing
Array.from(orderedMap.entries()).map(([yyyymmAskey, value]) => return <div></div>)
// result is same with using Object
{
"2024-12" : {...values},
"2025-01" : {...values},
"2025-05" : {...values},
}