This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

item

Summary

item returns the indexth File object in the FileList. If there is no indexth File object in the FileList, then this method must return null.

Method of apis/file/FileListapis/file/FileList

Syntax

var  = FileList.item(index);

Parameters

index

Data-type
unsigned long

The FileList index (starting from 0) of the File object to return.

Return Value

Returns an object of type DOM NodeDOM Node

Type: HRESULT

This method can return one of these values.

S_OK

Examples

This example lets you select one or more files, then uses the filelist length to report each filelist item’s name and last modified date/time.

<input type="file" multiple id="myfileinput"><br/>
<input type="button" value="Show file names and last modified dates" onclick="shownd()">
<p>. . .</p>
<script>
function shownd() {
  var fileinp = document.getElementById("myfileinput");
  var filelist = fileinp.files;
  alert(filelist.length);
  for (var i = 0; i < filelist.length; i++) {
    alert(filelist.item(i).name + " was last modified: " + filelist.item(i).lastModifiedDate);
  }
}
</script>

Notes

The first File object in a list of files called selectedFiles can be accessed by either of the following methods:

  • selectedFiles.item(0)
  • selectedFiles[0]

Related specifications

W3C File API Specification
W3C Working Draft

Attributions