6

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
      }
    })

1 Answer 1

12

.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);
Sign up to request clarification or add additional context in comments.

1 Comment

didn't know about Array.from() but that's what I was looking for after all :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.