files/en-us/web/api/hiddevice/collections/index.md
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_worker_except_shared")}}
The collections read-only property of the {{domxref("HIDDevice")}} interface returns an array of report formats
An array of report formats. Each entry contains the following:
usagePage
: An integer representing the usage page component of the HID usage associated with this collection. The usage for a top level collection is used to identify the device type.
Standard HID usage values can be found in the HID Usage Tables document
usage
type
: An 8-bit value representing the collection type, which describes a different relationship between the grouped items. One of:
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x07 to 0x7F
0x80 to 0xFF
More information on these types can be found in the Device Class Definition document.
children
inputReports
inputReport items which represent individual input reports described in this collection.outputReports
outputReport items which represent individual output reports described in this collection.featureReports
featureReport items which represent individual feature reports described in this collection.The following example demonstrates how to access the various elements once the collections property has been returned. You can see more examples, and live demos in the article Connecting to uncommon HID devices.
for (const collection of device.collections) {
// A HID collection includes usage, usage page, reports, and subcollections.
console.log(`Usage: ${collection.usage}`);
console.log(`Usage page: ${collection.usagePage}`);
for (const inputReport of collection.inputReports) {
console.log(`Input report: ${inputReport.reportId}`);
// Loop through inputReport.items
}
for (const outputReport of collection.outputReports) {
console.log(`Output report: ${outputReport.reportId}`);
// Loop through outputReport.items
}
for (const featureReport of collection.featureReports) {
console.log(`Feature report: ${featureReport.reportId}`);
// Loop through featureReport.items
}
// Loop through subcollections with collection.children
}
{{Specifications}}
{{Compat}}