I have this function
function initRegion(region) {
$.get( "/checkout/county", function( data ) {
$(region).each(function(){
var currentRegion = $(this);
var previousValue = currentRegion.data('value');
$.each(data, function (i, variable) {
var option = $('<option>', {value: variable, text: variable});
if(previousValue == variable){
option.prop('selected', true);
}
currentRegion.append(option);
});
});
});
region.select2();
}
I want to check if "option" already exists in list before appending it, and if it doesn't then append it to list. How can I check that?