So I have two scenarios, one where the array looks like ["20, "21", "22", "23", "24"] and I'm able to successfully loop through the array to create an object with each array value is the object key (i.e. {"20": [],"21": [],"22": [],"23": [],"24": []}). This is working as intended. The problem occurs when I have an array like ["24", "23", "22", "21", "20"], and when this is looped over, it creates an object exactly like the first scenario {"20": [],"21": [],"22": [],"23": [],"24": []}, when I need it to be {"24": [],"23": [],"22": [],"21": [],"20": []}. I have no clue what could be going on as I've read that javascript objects maintain their order
let numberObject = {};
["20", "21", "22", "23", "24"].forEach((date) => {
numberObject[date] = [];
});
Output: {"20": [],"21": [],"22": [],"23": [],"24": []}
let numberObject = {};
["24", "23", "22", "21", "20"].forEach((date) => {
numberObject[date] = [];
});
Output: {"20": [],"21": [],"22": [],"23": [],"24": []}
Expected output: {"24": [],"23": [],"22": [],"21": [],"20": []}
Any idea why the expected output isn't occurring?