0

i'm working in input file image "preview / remove" feature, but i found this error on remove image selected feature:

splice is not a function(…)

On click remove i have this code:

HTML:

<input id="pictures" type="file" class="inputfile" name="image[]" multiple required>

JS

$('body').on('click', '.removeImage', function(e){

                e.stopImmediatePropagation();
                // name file removed
                var namefileRemoved = $(this).parent().parent()[0].id;
                // get array images selected
                var elm=$('#pictures')[0].files; 
                // get position element in array and delete it.
                for(var i = 0; i < elm.length; i++) {
                   if(elm[i].name === namefileRemoved) {
                     elm.splice(0, i);
                   }
                }
                // remove image display html
                $(this).parent().parent().parent().remove();
});

My var elm=$('#pictures')[0].files; return enter image description here

i tried to search similar question but i did not find the solution! Thank you for your help!

Diego Cespedes
  • 1,353
  • 4
  • 26
  • 47
  • 1
    As you can see in the log itself the object is not of type `Array` its of type `FileList` and hence the splice is not working. – Subir Kumar Sao Dec 04 '16 at 17:38
  • 2
    Heres a link to an answer about deleting files from FileList. http://stackoverflow.com/questions/3144419/how-do-i-remove-a-file-from-the-filelist – Subir Kumar Sao Dec 04 '16 at 17:42

1 Answers1

0

Try slice instead of splice. I doubt that's what wrong here.