Vladimir Kornea Vladimir Kornea - 3 months ago 17
Javascript Question

Why isn't the FileList object an array?

Documentation: https://developer.mozilla.org/en-US/docs/Web/API/FileList

Why is

FileList
an object rather than an array? The only property it has is
.length
and the only method it has is
.item()
, which is redundant (
fileList[0] === fileList.item(0)
).

Answer

Well, there could be several reasons. For one, if it were an array, you could modify it. You can't modify a FileList instance. Secondly but related, it could be (probably is) a view onto a browser data structure, so a minimal set of capabilities makes it easier for implementations to provide it.

Comments