I am new to JavaScript, so please feel free to correct any technical terminology I use.
Currently, I have a collection of key-value pairs that are being added to a list. This list is being presented as a dropdown menu where the keys serve as options displayed on screen and the values are stored in the HTML tags. My supervisor has requested that I arrange these options alphabetically.
To achieve this, I have utilized a for...in loop to go through the object, extracting each value linked to its key into an array. After sorting the array, I can now add the values back to the list in alphabetical order.
Could someone advise me on the best approach to maintain the connection between keys and their respective values when adding them to the list after sorting?
Thank you.
SUMMARY: How can I ensure that keys remain associated with their values after organizing only the values in an array and sorting it alphabetically?