Remove Dropdown options which are previously selected?

I have multiple dropdowns as shown below:

The data for dropdown is coming from a list returned by js query.

When I select an Option in 1st dropdown, it should be removed from selection list of all the other dropdowns?

I was able to achieved the above functionality to some extend using the following js query:

// Assuming data is the JSON you provided
const data = sqlquery.data;

// Initialize an array to store the formatted values
const formattedValues = [];

// Iterate over the id array (assuming id is present in all arrays)
data.id.forEach((id, index) => {
  const size = data.size[index];
  const orderName = data.order_name[index];
  const color = data.color[index];

  // Create the formatted string
  const formattedString = `${size}-${orderName}-${color}-(${id})`;

  // Check if the formatted value is not present in any of the specified variables
  const isValueNotPresent = ![
    dropdown1.value,
    dropdown2.value,
    dropdown3.value,
    dropdown4.value,
  ].includes(formattedString);

  // If the value is not present, push it to the array
  if (isValueNotPresent) {
    formattedValues.push(formattedString);
  }
});

// Return the array of formatted values
return formattedValues;

the issue with the above script is the values disappear as they get removed from the list. So, We need to use a constant to store the values somewhere?