I have a list of photo on the page, each have an unique id, user can click on them to toggle select the photo, when they click the submit button, I need to send the array of selected photo ids to the back end, in the order that the photo was selected.
I think that the fastest way to track if a photo is selected is to use an object that use photo id as key, like:
var selected = {
"6272861": true,
"6272888": true
}
when the user unselect a photo, I just need to delete selected["6272861"].
But this will ignore the order, if I use an array to keep the selected photos:
var selected = ["6272861", "6272888"];
then when I need to unselect a photo, I have to loop through the array and delete the item.
Is there better ways? thanks.