I've been scratching my head for the last 30 minutes. I have an object that gets its keys sorted alphabetically even though the keys are not integers but strings. So basically I initiate an empty object as part of state in React.
const [answers,setAnswers] = useState({})
Then assign dynamically the key/value pairs depending on the user's answer at each particular question using the spread operator.
setAnswers({[toAsk[currentQuestion].q] : answer, ...answers})
That's all I do and I need the key value pairs to stay in the order they were added. However they get ordered alphabetically. I have no idea what is going on as I know that only keys that are integers have this behavior