Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The keys() method in the XRInputSourceArray interface returns a JavaScript iterator which can then be used to iterate over the keys used to reference each item in the array of input sources.





Return value

A JavaScript iterator that can be used to walk through the keys for each entry in the list of input sources. The values returned by the iterator are the indexes of each entry in the list; that is, the numbers 0, 1, 2, and so forth through the index of the last item in the list.


This example snippet gets the list of inputs for a session and tries to handle each type of input device it supports using.

for (const inputIdx of xrSession.inputSources.keys()) {
  /* the keys are the indexes into the list of inputs */

Here, for...of is used to iterate over each of the keys. For each key, the input is retrieved using the index with array notation: xrSession.inputSources[inputIdx].


Specification Status Comment
WebXR Device API
The definition of 'XRInputSourceArray' in that specification.
Working Draft XRInputSourceArray interface

[1] See Iterator-like methods in Information contained in a WebIDL file for information on how an iterable declaration in an interface definition causes entries(), forEach(), keys(), and values() methods to be exposed from objects that implement the interface.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
keysChrome Full support 79Edge Full support 79Firefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android Full support 79Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 11.2


Full support  
Full support
No support  
No support

See also