W3cubDocs

/Web APIs

XRInputSourceArray: keys() method

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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.

Syntax

js

keys()

Parameters

None.

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.

Examples

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

js

for (const inputIdx of xrSession.inputSources.keys()) {
  /* the keys are the indexes into the list of inputs */
  checkInput(xrSession.inputSources[inputIdx]);
}

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].

Specifications

No specification found

No specification data found for api.XRInputSourceArray.keys.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
keys 79 79 No No 66 No No 79 No 57 No 11.2

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceArray/keys