# The Object keys() method

> Learn how JavaScript Object.keys() returns an array of an object's own enumerable string property names, and which properties it leaves out.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-04-12 | Updated: 2026-07-18 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-object-keys/

`Object.keys()` returns an array containing an object's own enumerable string property names.

```js
const car = {
  color: 'blue',
  brand: 'Ford',
  model: 'Fiesta'
}

Object.keys(car) //['color', 'brand', 'model']
```

You can use the result with any array operation:

```js
for (const key of Object.keys(car)) {
  console.log(key, car[key])
}
```

See the [MDN `Object.keys()` reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) and the [ECMAScript specification](https://tc39.es/ecma262/2026/multipage/fundamental-objects.html#sec-object.keys) for the exact enumeration order and coercion rules.

## Which properties are included?

`Object.keys()` only includes properties that are:

- owned directly by the object
- enumerable
- keyed by strings

It leaves out inherited properties, non-enumerable properties, and Symbol-keyed properties:

```js
const id = Symbol('id')
const vehicle = { wheels: 4 }
const car = Object.create(vehicle)

car.brand = 'Ford'
car[id] = 123

Object.defineProperty(car, 'serialNumber', {
  value: 'ABC123',
  enumerable: false
})

Object.keys(car) //['brand']
```

Use these related methods when you need different data:

- `Object.values()` returns the corresponding values
- `Object.entries()` returns `[key, value]` pairs
- `Object.getOwnPropertyNames()` also includes non-enumerable string keys
- `Object.getOwnPropertySymbols()` returns own Symbol keys

Strings are converted to wrapper objects, so their character indexes are returned:

```js
Object.keys('hello') //['0', '1', '2', '3', '4']
```

Passing `null` or `undefined` throws a `TypeError`.
