Here's my ReactNative code.
// measurements are loaded from a jsonb column in postgres (supabase)
const measurements = loadFromDb();
console.log('measurements:', measurements);
console.log('typeof measurements:', typeof measurements);
console.log('Object.keys:', Object.keys(measurements));
console.log('JSON.stringify(measurements)', JSON.stringify(measurements))
const jsonMeasurements = {"Hip": "33", "Skirt length": "20", "Thigh": "44", "Top length": "", "Top waist": "", "Waist": "33"};
console.log('Json Object.keys:', Object.keys(measurements));
Outputs
measurements: {"Hip": "33", "Skirt length": "20", "Thigh": "44", "Top length": "", "Top waist": "", "Waist": "33"}
typeof measurements: object
Object.keys: ["Hip", "Thigh", "Waist", "Top waist", "Top length", "Skirt length"]
JSON.stringify(measurements): {"Hip":"33","Thigh":"44","Waist":"33","Top waist":"","Top length":"","Skirt length":"20"}
JSON Object.keys: ["Hip", "Skirt length", "Thigh", "Top length", "Top waist", "Waist"]
Why are the keys rearranged when loaded from supabase but not from an inline json?
As you can see if I inline init the measurements object with json object, the order is not altered.
My guess is measurements object loaded from db is not a object.