Favorites

JavaScript Object.keys() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Object.keys()
JavaScript Object Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Object.keys() static method returns an array of an object's own property names.

Description

The Object.keys() static method returns an array of the object's own enumerable property names. Inherited properties, non-enumerable properties and symbol keys aren't included. Integer-like keys are listed first in ascending order, then other strings in the order they were added.

Object.keys(obj).length is a quick way to count properties or check whether an object is empty.

Passing a primitive converts it to an object first, so Object.keys('ab') gives ['0', '1'], while null and undefined throw a TypeError. To include symbol keys or non-enumerable properties, use Reflect.ownKeys().

Syntax

Object.keys(obj)

Parameters

  • objThe object to work with.

Return Value

An array of the object's own enumerable string property names.

Example

const user = { name: 'Sam', age: 30, role: 'admin' };
console.log(Object.keys(user));
console.log(Object.keys(user).length);
console.log(Object.keys({}).length === 0);
console.log(Object.keys(['a', 'b']));

Browser Support

The following information will show you the current browser support for the Object.keys() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee