FormData Key As Array
I am trying to setup a multiple file upload, using FormData html5 api. The problem is that i cannot delete index of an array that is on FormData key. ex: if(editor.frmData){
Solution 1:
You could use this function to delete one of many values for the same name:
function formDataDelete(frmData, name, index) {
var keep = frmData.getAll(name);
keep.splice(index, 1);
frmData.delete(name);
keep.forEach( value => frmData.append(name, value) );
}
It just deletes the name (and thus all values associated with it), and adds all values again, except the one that was at the indicated index.
Solution 2:
You can't.
There is set to set a key, and also append which will do the same thing without overwriting the existing key with the same name.
But set has its opposite in delete, append doesn't have an opposite.
The only way to do it is to delete the key and then rewrite all the values you want to keep to it.
Post a Comment for "FormData Key As Array"