Select2 search not applying for options created through Javascript

Hi everyone! I am using HTML, CSS, Bootstrap, JS and Jquery for my app. I have used Select2 Search on Dropdowns in multiple forms. The search works fine for options in select tag that are hard-coded in HTML file. If I populate the options from my JS file via an API response, the select2 doesnot apply on any of the select tags.

let inputTag = '';
        if (fieldType === 'select') {
            inputTag = `<div id="${field.key}_div" class="row mb-2"> 
                            <div class="col-md-3"><label for="${field.key}">${field.ui.label.toUpperCase()}</label></div>
                            <div class="col-md-9"><select class="form-control js-example-data-array" id="${field.key}" name="${field.key}" ${multipleTag} ${requiredTag} >${options}</select></div>
                        </div>`

what should I do?