$("#dynamicAttributes").val(null).trigger("change");
var newArray = [];
let newData = $.grep($('#select2').select2('data'), function (value) {
return value['id'] != id_to_remove;
});
newData.forEach(function(data) {
newArray.push(+data.id);
});
$('#select2').val(newArray).trigger('change');