XRInputSourceArray.keys() - Web APIs 编辑
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.
Syntax
xrInputSourceArray.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.
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
Specification | Status | Comment |
---|---|---|
WebXR Device API The definition of 'XRInputSourceArray' in that specification.1 | 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
BCD tables only load in the browser
See also
- Inputs and input sources
- The
XRInputSourceArray
methodvalues()
- The
Array
methodkeys()
XRInputSource
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论