Gamepad.index

The Gamepad.index property of the 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.

SyntaxEdit

readonly    attribute long                index;

ExampleEdit

window.addEventListener("gamepadconnected", function() {
  var gp = navigator.getGamepads()[0];
  gamepadInfo.innerHTML = "Gamepad connected at index " + gp.index + ": " + gp.id + ".";
});

Value

An integer.

SpecificationsEdit

Specification Status Comment
Gamepad
The definition of 'Gamepad.index' in that specification.
Working Draft Initial definition

Browser compatibilityEdit

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
General support 21.0 webkit
35.0
29.0 (29.0) Not supported 15.0 webkit
22.0
Not supported

See alsoEdit

Using the Gamepad API

Document Tags and Contributors

 Contributors to this page: Sebastianz, fscholz, teoli, chrisdavidmills
 Last updated by: Sebastianz,