Preselecting value in select2

The solution that worked for me (and that is decribed in the documentation) was:

$('#mySelect2').val('1'); // Select the option with a value of '1'
$('#mySelect2').trigger('change'); // Notify any JS components that the value changed

In case anybody wants to know how to solve this

$("#e6").select2('data', {id: '1049', text: 'MyLabel'});

You can use initSelection method

initSelection: function(element, callback) {
callback({id: 1, text: 'default selection with id 1' });
},

Check this link and loading remote data section here


in 2019 this worked for me

    // Create a DOM Option and pre-select by default~
    var newOption = new Option(data.text, data.id, true, true);
    // Append it to the select
    $('#mySelect2').append(newOption).trigger('change');