I am using this jquery code below to put a list of countries into a select option and set the user's country as the default.
If I console log, the code shows I am recognising the user country correctly and in my project it has a blank where "United Kingdom" should be and that option is selected, it is just blank.
Why is this and what I should try doing differently?
const sortedData = result.data.sort(); for (var i = 0; i < sortedData.length; i++) { if (sortedData[i] === userCountry) { $("#country-selector").append( $("<option selected>", { value: sortedData[i], text: sortedData[i], }) ); } else { $("#country-selector").append( $("<option>", { value: sortedData[i], text: sortedData[i], }) ); } } };```