0

I have file upload response as an object i need to delete this object when its clicked but its not working

my javascript code is :

var file_id = this;
var class_name = file_id.id;
for(var s=0;s<this.files.length;s++){
    console.log(this.files);
    Certificates.push(this.files[s]);
    form.append("doc", this.files[s], this.files[s].name);
    $("."+class_name).append('<span id="check'+ab+'"onmouseover="myclsFunction(this)" >'+this.files[s].name+'</span>');
    $("."+class_name).append('<img style = "border:0px;width:20px;display:none;margin-left: 8px;" id="clsimg'+ab+'" class="clsicon" src = "./images/closeRes.png" />');
    $("."+class_name).append('<br/>');
    console.log(form);
    console.log(this.files[s]);
    ab++;
}

this.files[s] is the object file and i need to delete it, how to delete this object?

Djave
  • 8,595
  • 8
  • 70
  • 124
Sabrilogesh K
  • 197
  • 4
  • 16
  • 1
    Not sure about your particular use case but usually `delete file[s]` deletes a given object. Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete – Edwin Clement Apr 01 '20 at 07:57
  • 1
    You can remove it from the `this.files` object by adding `delete this.files[s]` – Djave Apr 01 '20 at 07:57
  • As in https://stackoverflow.com/a/25919959/12540953 try delete this.files[s]; – Bendar Apr 01 '20 at 07:58

1 Answers1

1

You just need to set its value to null. Something looks like this.files[s] = null will do the job.

Hope it works!

RifkyLTF
  • 302
  • 4
  • 14