Hi,
You can refer to Select2 Docs to populate Select2 dynamically.
You can run your code after the core-js includes in the html within the document ready event in order to access the core plugins and components once they are loaded and ready:
// On document ready
KTUtil.onDOMContentLoaded(function () {
// your code
});