Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Object.keys

Returns an array of an object's property names.

Available since: ES5

Syntax

Object.keys(obj)

Parameters

ParameterTypeDescription
objobjectThe object whose properties to list.

Return value

ArrayAn array of strings with the property names.

Examples

Property names:

console.log(Object.keys({ name: 'Anna', age: 25 }).join(', '));

Output:

name, age

The companion Object.values() returns the values:

console.log(Object.values({ name: 'Anna', age: 25 }).join(', '));

Output:

Anna, 25

Notes

Object.keys(obj).length is a handy way to count an object's properties.

See also

Related recipes

In the tutorial

Thanks for reading!

Donate to the site — we work hard for you.