XRInputSourceArray
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
The interfaceXRInputSourceArray represents alive list of WebXR input sources, and is used as the return value of theXRSession propertyinputSources. Each entry is anXRInputSource representing one input device connected to the WebXR system.
In addition to being able to access the input sources in the list using standard array notation (that is, with index numbers inside square brackets), methods are available to allow the use of iterators and theforEach() method is also available.
In this article
Instance properties
The following properties are available onXRInputSourceArray objects.
lengthRead onlyExperimentalThe number of
XRInputSourceobjects in the list.
Instance methods
The following methods are available onXRInputSourceArray objects. You may also use the features of theSymbol type.
entries()ExperimentalReturns an
iteratoryou can use to walk the list of key/value pairs in the list. Each item returned is an array whose first value is the index and whose second value is theXRInputSourceat that index.forEach()ExperimentalIterates over each item in the list, in order from first to last.
keys()ExperimentalA list of the keys corresponding to the entries in the input source list.
values()ExperimentalReturns an
iteratoryou can use to go through all the values in the list. Each item is a singleXRInputSourceobject.
In addition to these methods, you may use array notation to access items in the list by index For example, the snippet of code below calls a functionhandleInput(), passing into it the first item in the input source list, if the list isn't empty.
let sources = xrSession.inputSources;if (sources.length > 0) { handleInput(sources[0]);}Specifications
| Specification |
|---|
| WebXR Device API> # xrinputsourcearray-interface> |