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
}
})
CodePudding user response:
.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);