Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use map on FileList array?

can i use map on FileList? the object is iterable so maybe there's some way to make it work with map?

for example:

    window.addEventListener('drop', e => {
      e.preventDefault();
      if(e.dataTransfer?.files) {
        const files = e.dataTransfer.files.map(f => f.path); // imaginary code
      }
    })
like image 537
Jack Avatar asked Sep 03 '26 17:09

Jack


1 Answers

.map() exists only on Array.prototype, not on FileList. But you can use Array.from() to convert any iterable object into an array, and then use the map function:

const files = Array.from(e.dataTransfer.files).map(f => f.path);
like image 83
Sumit Avatar answered Sep 06 '26 07:09

Sumit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!