class method Object.keys

View source on GitHub →

Object.keys(object) → Array
  • object (Object) – The object to pull keys from.

Returns an array of the object's property names.

Note that the order of the resulting array is browser-dependent — it relies on the loop, for which the ECMAScript spec does not prescribe an enumeration order. Sort the resulting array if you wish to normalize the order of the object keys.

Object.keys acts as an ECMAScript 5 polyfill. It is only defined if not already present in the user's browser, and it is meant to behave like the native version as much as possible. Consult the ES5 specification for more information.

// -> []
 Object.keys({ name: 'Prototype', version: '1.6.1' }).sort();
// -> ['name', 'version']