← All languages
JavaScript function of the day
Random

Object.keys

Return an array of an object's own enumerable property names.

Description

The Object.keys() method returns an array of a given object's own enumerable string-keyed property names. The order of the array matches the order returned by a for...in loop, except that Object.keys() does not include inherited properties.

This method is commonly used to iterate over the properties of a plain object, count properties, or convert an object into an array-based representation for further processing with array methods.

If a non-object value is passed, it is coerced to an object. Passing null or undefined throws a TypeError. For arrays, Object.keys() returns the indices as strings.

Arguments

NameDescriptionOptional
obj The object whose enumerable property names are to be returned. No

Example

Object.keys({ a: 1, b: 2, c: 3 });
// ['a', 'b', 'c']

Reference