Programatically create an optgroup label?

I’m programatically creating my pulldown like this:

var newOption = new Option("whatever the value", "test", false, false);
('#mySelect2').append(newOption).trigger('change');

That inserts a normal item, like this:

<select id="mySelect2" multiple="multiple">
	<option value="test">whatever the value</option>
</select>

But now I’d like to create an optgroup label programatically as well, to create this:

<select id="mySelect2" multiple="multiple">
	<optgroup label="Stuff">
		<option value="test">whatever the value</option>
	</optgroup>
</select>

I can’t find it in the manual:

https://select2.org/programmatic-control

Any tips by chance?