How to change filename on Files array using java script? [duplicate]

How can i change the uploading file name of files array. What i want is to remove any empty spaces from file name if exists, i have tried with this code but it doesn’t change the file name as expected, how can i update the file name for the files array.

async function formatFileName(inp) {
    var fileName = inp.files[0].name
    inp.files[0].name = "TEST1"
    console.log(inp.files[0].name)
}

async function saveFile(inp) {
    await formatFileName(inp)
    let formData = new FormData();
    formData.append("file", inp.files[0]);
    await fetch('{{ file_upload_api }}', { method: "POST", body: formData }).then(() => {
        $('#file_name').html(inp.files[0].name);
        alert("File Upload Succefully")
    }).catch((err) => {
        $('#file_name').html("Something went wrong uploading " + inp.files[0].name).css('color', 'red');
        alert(err)
    });
}

Thanks in advance.