Gamepad: index property
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("Gamepad API")}}
The **index** read-only property of the {{domxref("Gamepad")}} interface returns an integer that is auto-incremented to be unique for each device currently connected to the system.
This can be used to distinguish multiple controllers; a gamepad that is disconnected and reconnected will retain the same index.
Value
A {{jsxref("Number")}}.
Examples
js
window.addEventListener("gamepadconnected", () => {
const gp = navigator.getGamepads()[0];
gamepadInfo.textContent = `Gamepad connected at index ${gp.index}: ${gp.id}.`;
});Specifications
{{Specifications}}
Browser compatibility
{{Compat}}