yeah, my code was just for collecting the filenames.
i still would change this:
form.append(document.createElement('input'));
form.children[i].type = 'hidden';
form.children[i].name = 'selection';
form.children[i].value = v;
into this:
form.append(Object.assign(document.createElement('input'), { type:'hidden', name:'selection', value:v }));