Hi everyone,
I have some data that I am using to populate the options of an input selector. The data looks something like this:
{
"name": "Option 1",
"id": "899df70d-c13b-4a79-9627-febc354dc896"
},
{
"name": "Option 2",
"id": "a5119000-6c76-49c8-aa37-2cb89443edf7"
}
I used the map function to convert this to the below, so that it is accepted by my input selector
["Option 1", "Option 2"]
Now the problem is when the value changes, I need to grab the ID of the option that was selected, but this is no longer available because the ID of the option isn’t contained within the value itself.
In this simplified example, I could just use a function to find the id
where the value equals name
. But this doesn’t seem like a very polished solution (what if there are two options with the same name?).
What’s the best way to handle this?