Remove a FileList item from a multiple "input:file" in HTML5

When working with HTML5 file inputs, you cannot directly modify the FileList object returned by input.files. The FileList is read-only, so removing items requires converting it to an array first.

The Problem

The FileList object from file inputs is immutable:









Method 1: Convert to Array and Filter

Convert the FileList to an array, then filter out unwanted files:








Method 2: Remove by Index

Remove a specific file by its index position:








Method 3: Remove by Filename

Filter out files based on their names:









Key Points

  • FileList objects are read-only and cannot be modified directly
  • Use Array.from() to convert FileList to a modifiable array
  • DataTransfer API helps recreate a new FileList after modifications
  • Always check if files exist before attempting removal

Browser Compatibility

Method Chrome Firefox Safari
Array.from() 45+ 32+ 9+
DataTransfer 24+ 4+ 6+

Conclusion

Since FileList is read-only, convert it to an array using Array.from(), modify as needed, then recreate the FileList using DataTransfer. This approach provides flexible file management in HTML5 applications.

Updated on: 2026-03-15T23:18:59+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements